Skip to content
Advertisement

Getting the Axios response from inside the pipe function in javascript

Hello right now I am trying to upload media to Twitter via API and for that I need a value from a previous axios call.

This is my API call which inits the media upload:

JavaScript

Something like “response = await uploadMediaInit(exampleFormData)” returns a ConcatStream object.
How can I acquire the axios response?

Advertisement

Answer

Wrap a Promise around the fd.pipe method and return it from the function. This way you can resolve the promise whenever your axios request has completed.

Inside the concat function use async / await to await the axios request to get a response. Then resolve the promise with the response gotten from the request and your value will be available outside of the function.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement