2010-11-18 123 views
4

这里我有一个图片网址。文件名是图像的URL使用boto在s3上传图片

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") 

上传东西到S3,但它显示了错误:

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

+0

哪一行是抛出错误?在我看来,你的问题可能不在你粘贴的那段代码中。 – 2010-11-18 12:31:31

+0

这似乎是尝试在Firefox/Windows中打开JPEG图像时得到的错误消息。您可以随时使用Windows照片查看器打开JPEG图像。检查您打开* .jpg和* .jpeg文件的应用程序在Firefox或Windows中是否正确关联。 – scoffey 2010-11-18 15:54:20

回答

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

此行有一些语法错误。用。。。来代替 。

检查您尝试阅读的图像文件的文件权限。从错误信息看起来像你,或者至少你的程序没有读取该文件的权限。

5

我很确定images/jpeg是一个错字。正确的mimetype是:

image/jpeg