Reputation: 2033
I want to fetch some data from a server and send it to another server. The data involved is a file. Is there any way to directly send the received file to the next axios request without saving it in the filesystem first?
I've tried something like:
let res = axios({
method: 'get',
url: 'someurl.com/image.png',
responseType: 'stream'
})
axios.post(url2, {data: res.data}, {headers:{'Content-Type':'multipart/form-data'})}
and it doesn't seem to work.
So is there any way to do the above? Or should I go about it in a different manner?
Upvotes: 3
Views: 632
Reputation: 874
Try this if you are using async/await
const { data } = await axios.get('/some_url', {...configs, responseType: 'stream'})
// pass it to another request
await axios.post('/some_other_url', data, config)
Upvotes: 2
Reputation: 1099
axios
call returns a promise. Can you try the following snippet and see if it works?
axios({
method: 'get',
url: 'someurl.com/image.png',
responseType: 'stream'
}).then((res) => {
axios.post(url2, {data: res.data}, {headers:{'Content-Type':'multipart/form-data'})}
});
Upvotes: 0