我试图使用Aws sdk rails gem上传文件。
一切都很成功,除非我找不到如何使用ruby sdk将文件上传到特定文件夹的方法。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="ip" />
<input type="button" value="Get country of IP" id="submit" />
<div id="content">
</div>
这很好用。但我想在aws存储桶中的特定目录中创建s3 = Aws::S3::Resource.new
obj = s3.bucket('storagy-teen-dev-us').object("deepak_file")
obj.upload_file('./tmp/aws_test.txt')
,让我们说deepak_file
。我已经尝试过以下但没有工作。
photos
答案 0 :(得分:7)
试试这个,
s3 = Aws::S3::Resource.new
path = 'photos/deepak_file/aws_test.txt'
s3.bucket('storagy-teen-dev-us').object(path).upload_file(./tmp/aws_test.txt)
您只需要指定带文件名的目录的完整路径。
答案 1 :(得分:0)
require 'aws-sdk-s3' # v1.x
client = Aws::S3::Client.new(region: '...',
access_key_id: '...',
secret_access_key: '...')
client.put_object(bucket: bucket,
key: 'photos/my-pic.jpg',
body: File.read(some_image_file),
acl: 'private')