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

How to post images/files ? #208

Open
shivekkhurana opened this issue Sep 3, 2015 · 3 comments
Open

How to post images/files ? #208

shivekkhurana opened this issue Sep 3, 2015 · 3 comments

Comments

@shivekkhurana
Copy link

I'm using the following code to post image to backend :

    post('/admin/update/'+id, {
      name: name,
      cover_picture: coverFile
    })
      .then(function(response) {
         ...
      })
      .fail(function(err) {
        ...
      })
    ;

The post() function adds api keys and handles expired tokens and uses reqwest under the hood. coverFile is an instance of File. The api works with postman but when I checked for the file being sent via reqwest, it returned false. No file is being sent with reqwest. How to fix this ?

Possible duplicate : #135

@moklick
Copy link

moklick commented Jan 19, 2016

This works for me:

let formData = new FormData();
formData.append('file', file);

reqwest({
  url: API_URL,
  method: 'post',
  crossOrigin: true,
  processData: false,
  data: formData
}).then(res => console.log(res));

processData=false seems to be the important option

@anisjonischkeit
Copy link

This worked for me too. Thanks

@yangfan0095
Copy link

it worked for me too 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants