multipart form data submit with restangular
See original GitHub issueI have to submit a form which includes a user selected file to the server. I can get this working using $http directly as below,
var fd = new FormData();
fd.append("profile",angular.toJson(profile));
fd.append("file", file);
return $http.post("/server/api/profile/me/bio", fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
});
I tried to do the same submit using restangular as below return userAPI.one(‘me’).customPOST(fd,“bio”,{}, {‘Content-type’:undefined});
However this doesn’t do the multipart submit correctly and attempts to send a empty payload request. I suspect this is because I need to specify the transformRequest flag to address this issue: https://github.com/angular/angular.js/issues/1587
Is there a way to do set a request transformer just on this request?
Thanks
Issue Analytics
- State:
- Created 10 years ago
- Comments:27 (6 by maintainers)
Top Results From Across the Web
how to upload a file in Restangularjs using multipart/formdata
This piece of code worked for me.... $scope.uploadFiles = function(file) { console.log(file); $scope.fileData = file; var fd = new FormData(); ...
Read more >Using FormData Objects - Web APIs | MDN
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending...
Read more >Ngx-restangular: RESTful API Angular Solution - 2muchcoffee
Ngx-restangular is a custom-made Angular 2+ solution that simplifies common GET, POST, DELETE, and UPDATE requests with a minimum of client code ...
Read more >restangular-shlatchz - npm
Restangular is an AngularJS service that simplifies common GET, POST, DELETE, ... the request to use the Content-Type: multipart/form-data as the header.
Read more >Angular 8 + Spring Boot: File upload example - BezKoder
Spring Boot Multipart File upload (to static folder) example ... FormData is a data structure that can be used to store key-value pairs....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a workaround for setting default headers. Instead of setting undefined, set a function returning undefined:
Hi, All seems to be OK when you don’t set global default headers. When adding the following default values in config step, form data are posted without requested headers : form-data and boundary but with ‘application/json’. RestangularProvider.setDefaultHeaders({ “Content-Type”: “application/json”, “X-Requested-With”: “XMLHttpRequest” });
When removing “Content-Type”: “application/json” from config , customPOST(formData,‘’,undefined,{‘Content-Type’: undefined}) does its stuff.
Any idea?
Many thanks in advance.
Cheers