为什么通过 URL 上传到 S3 的文件没有扩展名?
我在 Heroku 上使用 s3 上传图片没有问题。
我还有一种方法可以让用户从网址上传。
不幸的是,似乎当使用这种方法上传图片时,它们保存时没有文件扩展名。
所以我得到了这种图像网址的链接......
如果相同的图像已上传到本地,它将如下所示:
http://s3.amazonaws.com/mysite/images/23/original< /a>.JPG?1311799466
在我的 pic
模型中,这是我用来允许通过网址上传的代码:
def download_remote_image
begin
self.image = open(URI.parse(self.pic_url))
rescue
errors.add_to_base("- something is wrong with the image url.")
return false
else
return true
end
end
有什么想法吗?
I've got picture uploads working with s3 on heroku no problem.
I also have a method that enables users to upload from a web-address.
Unfortunately, it seems as though when pictures are uploaded using this method they are saved without their file extension.
So I get this sort of link for image urls...
http://s3.amazonaws.com/mysite/images/23/original.?1311799466
If the same image had been uploaded locally it would look like this:
http://s3.amazonaws.com/mysite/images/23/original.JPG?1311799466
In my pic
model this is the code I'm using to allow uploads via web addresses:
def download_remote_image
begin
self.image = open(URI.parse(self.pic_url))
rescue
errors.add_to_base("- something is wrong with the image url.")
return false
else
return true
end
end
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对此进行更改:
小心,最新版本的 Paperclip 在遇到 io 对象而不是 File 时会抛出错误,不确定他们是否修复了该问题。
Change with this:
Careful, recent versions of Paperclip throw errors when encountering a io object instead of File, not sure if they fixed that.
由于您使用的是回形针,因此应该使用回形针生成图片网址,例如:
since you are using paperclip the picture url should be generated with paperclip such as: