How angular post multipart/form-data file to grails?

2,322 views
Skip to first unread message

Reddy

unread,
Jan 1, 2013, 10:14:12 PM1/1/13
to ang...@googlegroups.com
Hi guys,
i have angular controller

<input type="file" id="img" name="img" ng-model="modelInstance.img"/>

$http.post("article/save",{
params:modelInstance,
data:files,
headers: {'Content-Type': 'multipart/form-data'}
}).success(function(data){
if(data.bindingFailure!=false){
window.location = "#/article/list";
}else{
$scope.errors = data.defaultMessage;
}
})

and then grails controller

def save() {
def f = request.getFile(request.JSON.params.img)
       }

and get nothing with params.img, when i println request.JSON.params.img show null
how can i bind params.img from angular to grails? thanks

Joshua Miller

unread,
Jan 2, 2013, 1:03:05 AM1/2/13
to angular
Hi!

That's not really enough information to go on, as context is everything. But what does Firebug or Chrome Developer Console show being sent? If you can see the appropriate request, then this is a grails problem. If you can't, show us a minimal Plunker or JsFiddle so we can help resolve the angular problem.

Josh


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 

Reddy

unread,
Jan 2, 2013, 1:46:43 AM1/2/13
to ang...@googlegroups.com
Hi Josh, 

ok, example when i upload a file, i want that file save to my folder local directory,
can angular do that thing?


thanks

Joshua Miller

unread,
Jan 2, 2013, 2:19:55 AM1/2/13
to angular
Hi!

Angular doesn't have a file upload directive baked in; however, you can write one, as others have done. Search this group for "file upload" and you'll find a few potential solutions. Unfortunately, I haven't personally tackled that problem, so I will defer to those who have.

Josh

Reddy

unread,
Jan 2, 2013, 3:00:03 AM1/2/13
to ang...@googlegroups.com

hi Josh,

ok already search this group, and maybe i must try to combine it with file-upload-jquery-plugin
thanks for the answer
Reply all
Reply to author
Forward
0 new messages