Tag: carrierwave

使用CarrierWave上传RESTful文件

我正在尝试为文件上传构建API后端。 我希望能够使用具有Base64编码的文件字符串的POST请求上传文件。 服务器应解码字符串,并使用CarrierWave保存文件。 这是我到目前为止所拥有的: photo.rb: class Photo include Mongoid::Document include Mongoid::Timestamps mount_uploader :image_file, ImageUploader end image_uploader.rb: class ImageUploader < CarrierWave::Uploader::Base storage :file def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end end Rails控制台:(摘要) ruby-1.8.7-p334 :001 > img = File.open(“../image.png”) {|i| i.read} => “\377 JFIF\000\001\002\001\000H\000H\000\000\377 Photoshop 3.0\0008BIM\003… ruby-1.8.7-p334 :003 > encoded_img = Base64.encode64 img => 3af8A\nmLpplt5U8q+a7G2… ruby-1.8.7-p334 :005 > p = […]

301 S3上传后永久移动

我试图使用carrierwave和雾gem将图像上传到Ruby on Rails上的S3,正确上传图像但是当我尝试保存包含刚刚上传的图像信息的模型时我得到了这个错误: Excon::Errors::MovedPermanently in UserController#show app/models/user.rb:46:in `process_image_with_key’ app/controllers/user_controller.rb:12:in `show’ <Excon::Response:0x007f97846a3c18 @body="\nPermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. 用户模型: mount_uploader :image, AvatarUploader def image_name File.basename(image.path || image.filename) if image end def process_image_with_key( key ) unless key.nil? self.key = key self.remote_image_url […]