Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS/Rails回形针文件上载_Javascript_Ruby On Rails_Angularjs_File Upload_Paperclip - Fatal编程技术网

Javascript AngularJS/Rails回形针文件上载

Javascript AngularJS/Rails回形针文件上载,javascript,ruby-on-rails,angularjs,file-upload,paperclip,Javascript,Ruby On Rails,Angularjs,File Upload,Paperclip,我试图使用回形针gem实现AngularJS/Rails文件上传。 我用指令修复了文件输入问题。 现在我想把这张图片和文章的其他数据一起发送,但是图片数据没有发送 HTML: <form name="PostForm" ng-submit="submit()" novalidate> <input type="text" ng-model="post.title"> <input type="file" file-upload /> <tex

我试图使用回形针gem实现AngularJS/Rails文件上传。 我用指令修复了文件输入问题。 现在我想把这张图片和文章的其他数据一起发送,但是图片数据没有发送

HTML:

<form name="PostForm" ng-submit="submit()" novalidate>
  <input type="text" ng-model="post.title">
  <input type="file" file-upload />
  <textarea ng-model="post.content"></textarea>
</form>
我的模型:

class Post < ActiveRecord::Base
  attr_accessible :content, :title, :image_file_name, :image_content_type, :image_file_size, :image_updated_at

  belongs_to :user
  has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
end

因此,没有使用图像的数据被发送到服务器,关于如何做的任何提示?

我现在进行,我成功地通过表单数据内容类型发送文件数据,问题现在在rails控制器中,启动了一个错误:

undefined method `stingify_keys`
以下是我用来发送数据的代码:

$http({
        method: 'POST',
        url: url,
        headers: { 'Content-Type': false },
        transformRequest: function (data) {
            var formData = new FormData();
            formData.append("post", angular.toJson(data.post));
            formData.append("image", data.image);
            return (formData);
        },
        data: { post: $scope.post, image: $scope.image}
    }).
success(function (data, status, headers, config) {
    alert("success!");
}).
error(function (data, status, headers, config) {
    alert("failed!");
});
这就是发送到rails的数据:

-----------------------------2122519893511
Content-Disposition: form-data; name="post" {"title":"sdsdsd","content":"sdsd"}
-----------------------------2122519893511
Content-Disposition: form-data; name="image"; filename="dad.jpg" Content-Type: image/jpeg [image-data]
-----------------------------2122519893511--

嗨@jeo-bow,你能用安圭拉语的回形针和rails上传图像吗?嘿,乔,这可能会有帮助
$http({
        method: 'POST',
        url: url,
        headers: { 'Content-Type': false },
        transformRequest: function (data) {
            var formData = new FormData();
            formData.append("post", angular.toJson(data.post));
            formData.append("image", data.image);
            return (formData);
        },
        data: { post: $scope.post, image: $scope.image}
    }).
success(function (data, status, headers, config) {
    alert("success!");
}).
error(function (data, status, headers, config) {
    alert("failed!");
});
-----------------------------2122519893511
Content-Disposition: form-data; name="post" {"title":"sdsdsd","content":"sdsd"}
-----------------------------2122519893511
Content-Disposition: form-data; name="image"; filename="dad.jpg" Content-Type: image/jpeg [image-data]
-----------------------------2122519893511--