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

Add support for Stream #296

Merged
merged 3 commits into from
Apr 21, 2016
Merged

Add support for Stream #296

merged 3 commits into from
Apr 21, 2016

Conversation

nickuraltsev
Copy link
Contributor

Fixes #2

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 91.716% when pulling d88bc12 on nickuraltsev:stream into 5c58b83 on mzabriskie:master.

@BlakeLucchesi
Copy link

@nickuraltsev Can you share any additional documentation on what is required to support upload streams on the server side? Also, if I stream data to the server does that mean the response has to be streamed back as well?

Really great job on the PR btw, updated tests and documentation are great!

@mzabriskie mzabriskie merged commit 093593c into axios:master Apr 21, 2016
@wilk
Copy link

wilk commented May 4, 2016

I didn't understand how this is implemented from axios.
Can I use axios with form-data on Node.js?

This is an example but it's not working:

var FormData = require('form-data'),
      axios = require('axios'),
      fs = require('fs'),
      data = new FormData();

data.append('something', 'something');
data.append('file', fs.createReadStream('myFile.md');

axios.post('http://localhost:12345/api', data, {headers: data.getHeaders()}).then(...).catch(...);

This doesn't send data to the server.
What's wrong with that code?

Thanks in advance,
Wilk

@nickuraltsev
Copy link
Contributor Author

@wilk The code looks good to me. Are you using the latest version of axios?

@wilk
Copy link

wilk commented May 5, 2016

Uhm, right: I'm using the 0.9.1 version. I think it doesn't support yet that feature, right?

@nickuraltsev
Copy link
Contributor Author

@wilk Right, it was implemented in 0.11.0

@wilk
Copy link

wilk commented May 6, 2016

@nickuraltsev right, it's working with 0.11.0, thanks ;)

@MikeCheel
Copy link

I think this is broken again. I am getting Error: write after end

@jeffijoe
Copy link

How do I specify a file name for the stream upload on the server? Usually when you send a HTML file from the browser, it has a file name which is sent to the server.

@digital-flowers
Copy link

@jeffijoe i don't think this is an issue when you create form data you can send the filename as another form data value formdata.append("filename",filename)

@jeffijoe
Copy link

Right but I think for it to be as agnostic as possible you would need to specify it in some way for libraries like busboy to pick it up

@isNeilLin
Copy link

var FormData = require('form-data');
var axios = require('axios');
var form = new FormData();
form.append('bookid',id);
form.append('classes',classes);
form.append('data',fs.createReadStream(__dirname + `${file}`));
axios.defaults.headers.common = form.getHeaders();
axios.post(`${baseUrl}/outline/create`,form)
.then((response)=>{
	console.log(response.data)
})
.catch(e=>{console.log(e)})

I try to post formdata,but not success because content-length
image

@Thinkscape
Copy link

Works fine... tested with recent versions:

    const form = new FormData();
    form.append('file', fs.createReadStream(path));
    
    const result = await this.client.post(`some/path`, form, {
       headers: form.getHeaders(),
    });

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

Successfully merging this pull request may close these issues.

Support file uploads
10 participants