开发者

How come files uploaded to S3 via URL have no extension?

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 thi开发者_运维问答s 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?


Change with this:

def download_remote_image
  begin
    io = open(URI.parse(pic_url))
    def io.original_filename; base_uri.path.split('/').last; end
    io.original_filename.blank? ? nil : io
  rescue
  end
end

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:

self.image(:thumb)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜