Replies: 3 comments
-
Can you elaborate on an issue and tag me? |
Beta Was this translation helpful? Give feedback.
-
const MY_FILE_PATH = './image.jpg';
const {size} = fs.statSync(MY_FILE_PATH);
const fileStream = fs.createReadStream(MY_FILE_PATH);
const upStream = await axios({
method: 'POST',
url: 'https://example.com/upload',
headers: {
'Content-Type': 'image/jpeg',
'Content-Length': size,
},
data: fileStream,
onUploadProgress: progressEvent => console.log(progressEvent.loaded)
}) The Edit: On an issue, alright, I create one. |
Beta Was this translation helpful? Give feedback.
-
This should work in Axios v1.0.0. Previously, Axios did not support progress capturing in the server environment, only for browser platforms. |
Beta Was this translation helpful? Give feedback.
-
Related: #961
So I use a stream (from a file) as
data
in an Axios request in order toPOST
the file bytes as request body (required by that endpoint), so no multipart/form body.This works fine now in recent Axios.
However, the
onUploadProgress
is never called. The reason for this is probably that a stream is used, and not a buffer orFormData
with the file added to it.As those files are larger, it would be nice to stream them anyway.
The
content-length
andContent-Length
headers are correctly set as Axios request header.Beta Was this translation helpful? Give feedback.
All reactions