mardi 31 mars 2015

How to fetch an image from one bucket and put it in another in S3 boto

I want to fetch an image from one bucket(bucket1) and put it another bucket (bucket2) I have written the below code snippet in python which I am trying,but I am getting the error:IOError: cannot identify image file.Please help.Thanks!



conn = boto.connect_s3()
filename='image2.jpg'
bucket=conn.get_bucket('bucket1')
key= bucket.get_key(filename)
fp = open (filename, "w+")
key.get_file (fp)


img = cStringIO.StringIO(fp.read())
im = Image.open(img)

b = conn.get_bucket('bucket2')
k = b.new_key('image2.jpg')
k.set_contents_from_string(out_im2.getvalue())




Aucun commentaire:

Enregistrer un commentaire