我还没有这样做,但我认为你必须使用paperclip。
将此行添加到您的 gemfile 中
gem "paperclip", "~> 2.4"
然后在你的图片模型中
has_attached_file :image, :styles => { :medium => "150x150>", :thumb => "50x50#" }
# you don't need the styles, I just put them there so you know you can.
进行迁移
class AddImageToPicture < ActiveRecord::Migration
def self.up
add_column :picture, :image_file_name, :string
add_column :picture, :image_content_type, :string
add_column :picture, :image_file_size, :integer
end
结束
运行迁移。
在你的 phonegap 应用程序中你可以做到。
<form accept-charset="UTF-8" action="/pictures" class="picture_user" enctype="multipart/form-data" id="new_user" method="post">
<input id="user_image" name="user[image]" type="file">
</form>
但可能有更好的方法来获取表单。未测试
更新
你可以试试这个。关键是为回形针发送正确的选项。使用回形针制作一个 rails 应用程序,并从表单中找到回形针发送到服务器的选项。然后将选项添加到 FileUploadOptions();
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, "http://some.server.com/upload.php", win, fail, options);