开发者

upload the image on s3 using boto

Here I have an image url. filename is image url

def upload(filename, content)
    conn = S3Connection(aws_access_key, aws_secret_key)
    b = Bucket(conn, bucket_name)
    k = Key(b)
    k.key = filename..split('/')[::-1][0]
    k.set_metadata("Content-Type", 'images/jpeg')
    k.set_contents_from_string(content)
    k.set_acl("public-read")

It upload things to the S3 but i开发者_JAVA技巧t shows the error:

/tmp/t.jpeg could not be opened, because the associated helper application does not exist. Change the association in your preferences.


I'm pretty sure images/jpeg is a typo. The correct mimetype is:

image/jpeg


k.key = filename..split('/')[::-1][0]

This line has some syntax error. replace .. with .

Check your file permission for the image file you are trying to read. From the error message it seems like you, or at least your program don't have read access to that file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜