【发布时间】:2013-02-21 19:25:36
【问题描述】:
我正在通过以下方式将来自服务器的图片文件保存在 S3 中的存储桶中:
request = urllib2.Request('http://link.to/file.jpg')
response = urllib2.urlopen(request)
jpg_data = response.read()
storage = S3BotoStorage(bucket='icanhazbukkit')
my_file = storage.open(path_to_new_file, 'w')
my_file.write(jpg_data)
my_file.close()
文件被写入,但在某个地方 MIME 上下文丢失了,保存的图像将返回Content-Type: binary/octet-stream,并且浏览器将尝试下载而不是在点击其 URL 时显示。
有什么办法可以缓解这种情况?
【问题讨论】:
-
我不熟悉这个你使用的库,但是当你上传文件到s3时,你需要在api调用中传递content-type header。
标签: amazon-web-services amazon-s3 boto django-storage