3

我正在使用此脚本http://valums.com/ajax-upload/让 Ajax 上传与 Ruby on Rails 一起使用

但是当我尝试在我的控制器操作上上传文件时,我只得到这个:

Parameters: {"qqfile"=>"Foo.png"}
{"qqfile"=>"Foo.png", "action"=>"ul_file", "controller"=>"upload_files"}

但我不能把它当作一个文件来做

thefile = params[:qqfile]

foo = thefile.original_filename.slice(thefile.original_filename.rindex("."), thefile.original_filename.length).downcase

我需要做什么才能让这个脚本与 Ruby on Rails 一起工作?

谢谢。

///////// 更新

这就是 JS 的样子



$(document).ready(function(){
    var uploader = new qq.FileUploader({
        // pass the dom node (ex. $(selector)[0] for jQuery users)
        element: $('#file-uploader')[0],
        // path to server-side upload script
        action: '/NzzT/upload_files/ul_file'
    });

});


4

2 回答 2

1

这是使用 CarrierWave 的一个很好的解决方案:

https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Upload-from-a-string-in-Rails-3 https://groups.google.com/forum/#!topic/carrierwave /KBn2WmrwRAs

语法看起来像这样,就像一个魅力:

file = CarrierwaveStringIO.new(params[:qqfile], request.raw_post)
于 2012-01-11T01:22:43.103 回答
1

我在此评论中发布的解决方案

我写 QqFile 是为了方便上传。以回形针为例

于 2011-04-14T10:20:13.490 回答