저는 Paperclip gem을 사용하여 AngularJS/Rails로 파일 업로드를 구현하려고합니다. 지시어로 파일 입력 문제를 해결했습니다. 이제 게시물의 다른 데이터로 이미지를 보내고 싶지만 이미지 데이터는 전송되지 않습니다.AngularJS/Rails Paperclip 파일 업로드
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>
내 컨트롤러 :
$scope.create = function() {
function success(response) {
console.log("Success", response)
$location.path("posts");
}
function failure(response) {
console.log("Failure", response);
}
if ($routeParams.id)
Post.update($scope.post, success, failure);
else
Post.create($scope.post, success, failure);
}
$scope.$on("fileSelected", function (event, args) {
$scope.$apply(function() {
$scope.post.image = args.file;
});
내 모델 :
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
하지만 서버 측에 보낼 때, 요청이 그런 식이다 :
{
"content":"Hey",
"created_at":"2013-08-31T17:54:32Z",
"id":17,
"image_content_type":null,
"image_file_name":null,
"image_file_size":null,
"image_updated_at":null,
"title":"Image",
"updated_at":"2013-08-31T17:54:32Z",
"user_id":4
}
그래서 이미지를 보존하는 데이터는 서버로 전송되지 않으므로 그 방법에 대한 정보를 얻으시겠습니까? 지금 진행
헤이 조,이 힘 도움은 https : //gist.github 데이터를 전송 .com/vajapravin/48059fd9d64bb42f012f513cebd391ea – vajapravin