Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 使用Python&;将文件移动到存储桶中的特定键;博托_Python 2.7_Amazon S3_Boto - Fatal编程技术网

Python 2.7 使用Python&;将文件移动到存储桶中的特定键;博托

Python 2.7 使用Python&;将文件移动到存储桶中的特定键;博托,python-2.7,amazon-s3,boto,Python 2.7,Amazon S3,Boto,使用boto将文件从一点复制到另一点时遇到问题。虽然我可以很容易地将它们复制到bucket的顶部“level”中,这很好……但是我的bucket是由无数个月键组成的,当我试图将文件复制到其中一个特定键时,我的代码就会挂起。例如,这可以工作,但会将文件放入“main bucket”部分,这不是我想要做的(bucket变成了s3://mybucket/myFile.tar.gz,而我确实需要将文件放入每月一次的文件夹中,比如s3://mybucket/201507/myFile.tar.gz): 但

使用boto将文件从一点复制到另一点时遇到问题。虽然我可以很容易地将它们复制到bucket的顶部“level”中,这很好……但是我的bucket是由无数个月键组成的,当我试图将文件复制到其中一个特定键时,我的代码就会挂起。例如,这可以工作,但会将文件放入“main bucket”部分,这不是我想要做的(bucket变成了s3://mybucket/myFile.tar.gz,而我确实需要将文件放入每月一次的文件夹中,比如s3://mybucket/201507/myFile.tar.gz):

但是,如果我试图将文件移动到目标存储桶中的特定月度文件中,我会挂断(没有错误-只是无休止的等待),因此这不起作用:

destbucket.copy_key(“DestSubFolder/201507/myFILE.tar.gz", srcbucket.name, source.key)
所以基本上想知道是否有人有使用boto在s3中将文件移动到子文件夹(子键?)的经验?(如您所见,需要移动到适当的每月文件夹中)
谢谢

我认为问题在于您调用的是
copy\u key(string,string,key)
而不是
copy\u key(string,string,string)
。第三个参数是键的字符串(文件名),而不是实际的键对象。您可以将密钥指定为字符串,也可以使用
source.key.name

这对我很有用:

>>> import boto
>>> conn=boto.connect_s3()
>>> destbucket=conn.get_bucket('bucket2')
>>> destbucket.copy_key('bar/file', 'bucket1', 'foo/file')
<Key: bucket2,bar/file>
导入boto >>>conn=boto.connect_s3() >>>destbucket=conn.get_bucket('bucket2') >>>destbucket.copy_键('bar/file','bucket1','foo/file')
它将
s3://bucket1/foo/file
复制到
s3://bucket2/bar/file

我认为问题在于您调用的是
copy\u key(string,string,key)
而不是
copy\u key(string,string,string)
。第三个参数是键的字符串(文件名),而不是实际的键对象。您可以将密钥指定为字符串,也可以使用
source.key.name

这对我很有用:

>>> import boto
>>> conn=boto.connect_s3()
>>> destbucket=conn.get_bucket('bucket2')
>>> destbucket.copy_key('bar/file', 'bucket1', 'foo/file')
<Key: bucket2,bar/file>
导入boto >>>conn=boto.connect_s3() >>>destbucket=conn.get_bucket('bucket2') >>>destbucket.copy_键('bar/file','bucket1','foo/file')
它将
s3://bucket1/foo/file
复制到
s3://bucket2/bar/file

约翰在这里提供了
boto

对于
bot3
,您可以执行以下操作

s3 = boto3.resource('s3')
dest = s3.Bucket('destinationbucket')
source= { 'Bucket' : 'sourcebucketname', 'Key': 'filename'}
dest.copy(source, 'destinationfilename')

它将从
sourcebucketname/filename
复制到
destinationbucket/destinationfilename

这里提供了
boto

对于
bot3
,您可以执行以下操作

s3 = boto3.resource('s3')
dest = s3.Bucket('destinationbucket')
source= { 'Bucket' : 'sourcebucketname', 'Key': 'filename'}
dest.copy(source, 'destinationfilename')

它将从
sourcebucketname/filename
复制到
destinationbucket/destinationfilename

如何使用ios sdk?Khunshan--如果您想问一些不同的问题,请创建一个新问题。我如何使用ios sdk?Khunshan--如果您想问一些不同的问题,请创建一个新问题回答这个问题。