我的客户正在尝试从黑莓和安卓手机上传图像。他们不喜欢发布 a) 表单参数或 b) 多部分消息。他们想要做的是只使用文件中的数据对 url 进行 POST。
这样的事情可以在 curl 中完成:
curl -d @google.png http://server/postcards/1/photo.json -X POST
我希望将上传的照片放入明信片模型的照片属性中并放入正确的目录中。
我在控制器中做这样的事情,但目录中的图像已损坏。我现在正在手动将文件重命名为“png”:
def PostcardsController < ApplicationController
...
# Other RESTful methods
...
def photo
@postcard = Postcard.find(params[:id])
@postcard.photo = request.body
@postcard.save
end
该模型:
class Postcard < ActiveRecord::Base
mount_uploader :photo, PhotoUploader
end