1

我试图用Aws sdk rails gem上传文件。把对象放在aws S3中的特定文件夹中ruby

一切都很成功,但我找不到如何使用ruby sdk将文件上传到特定文件夹的方法。

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。我已经尝试了下面的但不工作。

obj = s3.bucket('storagy-teen-dev-us').object("photos/deepak_file")

回答

3

试试这个,

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) 

你只需要用文件名指定目录的完整路径。

相关问题