Skip to content
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

posting with formdata not working #65

Closed
flogball00 opened this issue Apr 20, 2015 · 10 comments
Closed

posting with formdata not working #65

flogball00 opened this issue Apr 20, 2015 · 10 comments

Comments

@flogball00
Copy link

tried doing something like

var fileData = new FormData();
      fileData.append("File1", file);

return axios({
                    method: 'post',
                    url: response.data.ChunkUri,
                    data: fileData,

                });

this returned an error from the server saying that there was no file sent. But...

vs jquery which worked and the file uploaded successfully.


                var options = {
                    type: "POST",
                    url: response.data.ChunkUri,
                    data: fileData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function(e){
                            console.log("YAY:: " + e);
                    },
                    error: function(a){
                        console.log("failed:: ");
                    }

                };
                return $.ajax(options);
@flogball00 flogball00 changed the title posting with formdata not working, maybe posting with formdata not working Apr 20, 2015
@srph
Copy link

srph commented Apr 21, 2015

Can you put "not working" into detail?

@mzabriskie
Copy link
Member

@flogball00 are you still having this problem?

@flogball00
Copy link
Author

Yep, both axios and superagent were not able to transmit the filename. When i looked at the request payload, i would get something like "Content-Disposition: form-data; name="File1"; filename=""

@mzabriskie
Copy link
Member

Odd. I'll have to look into jQuery's source, and see what's different.

@kalaspuffar
Copy link

@flogball00: Have you tried to use the third argument for formData suppling the filename?

https://developer.mozilla.org/en-US/docs/Web/API/FormData/append

@pnkapadia6
Copy link

Any updates on this?

@nickuraltsev
Copy link
Member

As @kalaspuffar pointed out, filename can be passed as the third parameter to FormData#append:

fileData.append("File1", file, "file.js");

@ConAntonakos
Copy link

@nickuraltsev's answer in #318 (comment) really helped me out.

@besabellacyrus
Copy link

@ConAntonakos that is the solution to my problem.

@jasperf
Copy link

jasperf commented Jun 14, 2018

@ConAntonakos Would be great if you could share how you adjusted your code in the end. Working on passing data with .append now as well as it won't with my regular setup.

@axios axios locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants