Open billie66 opened 9 years ago
看来通过 carrierwave 上传文件到云存储上,是无法得到上传进度的。若用 jquery-file-upload 把文件直接传到云上,不经应用所在服务器,就能显示文件上传进度了
一篇博客 http://pjambet.github.io/blog/direct-upload-to-s3/
上面文章有点儿过时,下面这篇比较新,虽然都是直传到 s3, 但能帮助理解其过程
https://github.com/blueimp/jQuery-File-Upload/wiki/Upload-directly-to-S3
把文件直传到骑牛的 Gem, https://github.com/huobazi/qiniu_direct_uploader
通过 qiniu_direct_uploader 将图片直传到骑牛后,返回的参数。
{"etag"=>"Fl4mOeSU0xWGfJZDKqsVa4Akixo-", "fname"=>"cover.jpg", "fsize"=>"213680", "mimeType"=>"image/jpeg", "imageInfo"=>{"format"=>"jpeg", "width"=>"1800", "height"=>"2360", "colorModel"=>"ycbcr"}, "exif"=>{"ColorSpace"=>{"val"=>"sRGB", "type"=>"3"}, "Compression"=>{"val"=>"JPEG compression", "type"=>"3"}, "DateTime"=>{"val"=>"2014:12:24 10:38:43", "type"=>"2"}, "ExifVersion"=>{"val"=>"Exif Version 2.1", "type"=>"7"}, "FlashPixVersion"=>{"val"=>"FlashPix Version 1.0", "type"=>"7"}, "Orientation"=>{"val"=>"Top-left", "type"=>"3"}, "PixelXDimension"=>{"val"=>"1800", "type"=>"4"}, "PixelYDimension"=>{"val"=>"2360", "type"=>"4"}, "ResolutionUnit"=>{"val"=>"Inch", "type"=>"3"}, "Software"=>{"val"=>"Adobe Photoshop CS6 (Macintosh)", "type"=>"2"}, "XResolution"=>{"val"=>"72.0090", "type"=>"5"}, "YResolution"=>{"val"=>"72.0090", "type"=>"5"}}, "endUser"=>"", "key"=>"uploads/2015/02/13/Fl4mOeSU0xWGfJZDKqsVa4Akixo-/cover.jpg", "custom_fields"=>{"aaa"=>"1", "bbb"=>"2"}, "xyz"=>"100"}
这里的 key 值是图片存储到骑牛后的最终文件名
贴个文档链接,介绍了qiniu 的重定向上传和回调上传
在上传策略中设置了过期时间, expires_in 字段,单位为秒,比如把过期时间设为 360,而上传文件比较大,文件上传时间超过过期时间,则上传不能成功,返回 401 错误码(unauthorized),把过期时间延长,则不会报错
http://railscasts.com/episodes/383-uploading-to-amazon-s3?view=asciicast
原理应该相似,一个封装好的 GEM
https://github.com/waynehoover/s3_direct_upload