-
Notifications
You must be signed in to change notification settings - Fork 840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multipart form data submit with restangular #420
Comments
Hey, You can do that in the latest version of Restangular userAPI.one('me').withHttpConfig({transformRequest: angular.identity}).customPOST(...` That should work for you :). Also, all other $httpConfigurations can be set in that Please tell me if it worked and reopen if it didn't |
Thanks for the reply. I updated to the latest version and changed to use withHttpConfig as you mentioned, but it still didn't quite work. Now the request payload is not empty but has the string "[object Object]". Note that the object I am passing in ("fd") is a FormData object. |
Did you set there the withCredentials and contentType as well? It should be the same with those. Can you debug https://github.com/mgonto/restangular/blob/master/src/restangular.js#L457 and check what's being sent in to $http? You can compare that to see what's going on. |
Everything seems to be the same except the "data" attribute shows up in the debugger as "Object" instead of "FormData" when I used $http directly and put a breakpoint in angular.js. Since it's no longer a FormData object I think $http skips all the multipart handling stuff. I wasn't able to figure out where the passed in FormData object was being changed in the restangular codebase. When a formdata object is passed in think it should just preserve it. |
Typo - I meant is shows up as "Object" when using restangular, but shows up correctly as FormData object when using $http |
I know what it's. The problem is that I'm stripping Restangular stuff. As a hack go to elemFunction and remove StripRestangular part. If that works Ill get it fixed :) — On Thu, Nov 21, 2013 at 8:28 PM, zohebsait [email protected]
|
Yes! I temporarily commented out lines 918-921 shown below and it's works! I will work around till you push a fix. Thanks for your help.
|
Thank you. Ill leave this open meanwhile — On Thu, Nov 21, 2013 at 8:44 PM, zohebsait [email protected]
|
was this fixed? |
Not yet, please comment those lines temporarily. I haven’t had much time lately to work on this bugs, but I’ll try to work on them ASAP. Martin Gontovnikas Twitter: @mgonto (https://twitter.com/mgonto) On Wednesday, December 4, 2013 at 9:58 AM, Alonisser wrote:
|
Pushing fix :) |
great! Twitter:@alonisser https://twitter.com/alonisser On Mon, Dec 9, 2013 at 10:49 PM, Martin Gontovnikas <
|
This thread just saved my bacon, but I wasted some time trying to figure out how to set the headers correctly. Here's a solution that worked for me. It's Coffeescript. Sorry. Not my choice.
|
It still here, guys. I have same problem with 1.4
|
Hi, When removing "Content-Type": "application/json" from config , customPOST(formData,'',undefined,{'Content-Type': undefined}) does its stuff. Any idea? Many thanks in advance. Cheers |
+1 |
Hi! I'm trying to implement this but can't figure it out with my use case since it seems that How can achieve that functionality using the service approach? Thanks in advance. |
It seems that Nevertheless, in my Entities service I changed |
I'm having the exact same issue with using httpConfigs for objects created with .service I have provided a PR, because I think this is a bit of a inconsistency. See #1068 |
Thanks for comments and code snippets. It helps quite a lot! I have a working implementation but I'm halfly satified because it uses Base64-encoded data upload which seems less efficient than Multipart Upload, and would not work with heavy file (as far as I understood). @deltaepsilon I tried your code but it only sends the file itself, whereas I would like to update my user during the same call. It should be possible as that's what a regular form does. Here's the code: View:
Controller:
Simply calling But how can I have a
I'll report final working solution. Thanks a lot! |
Any progress on this? I'm having the same problem. :( |
I'm using jsPDF to create a PDF then i try to submit it with |
@ncourtial, the default headers problem is fixed like so: |
if i set ["Content-Type"] = undefined, It calls webservice , but i i want to send text data in other language (utf-8) it won't receive as expected in Rest api |
I found a workaround for setting default headers. Instead of setting undefined, set a function returning undefined:
|
I can't seem to have it work.. this is what I'm using: I'm using restangular 1.51 with angular 1.6. My html looks like this
and the angular code:
laravel code:
thing is the $file here is appearing as an empty array in the laravel dump. The documentation is pretty bad on this. Ideas? |
so basically i had to brute force the content-type to btw i'm using restangular 1.51.. more details here https://stackoverflow.com/questions/49077674/how-to-upload-files-with-angular-using-cors/49081727#49081727 |
I have to submit a form which includes a user selected file to the server. I can get this working using $http directly as below,
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: angular/angular.js#1587
Is there a way to do set a request transformer just on this request?
Thanks
The text was updated successfully, but these errors were encountered: