RequestContentLengthMismatchError when uploading file with read stream #1837
-
I have this piece of code for uploading a file using a read stream const { size } = await fs.promises.stat(filePath);
listeners.onFileSize({ size, filePath });
const urlObj = new URL(url);
const fileReadStream = fs.createReadStream(filePath);
fileReadStream.on('data', () => {
listeners.onProgress({ total: fileReadStream.bytesRead, filePath });
});
headers['Content-Length'] = size;
headers['User-Agent'] = 'Electron/1.0';
headers['Accept-Encoding'] = 'gzip, deflate, br';
headers['Accept'] = '*/*';
headers['Host'] = urlObj.host;
const response = await request(url, {
method: 'PUT',
body: fileReadStream,
headers,
}); I get the following error I tried removing In the source code I see undici is using
what am I missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You are starting the stream prematurely by registering the data listener. Call pause after registering the listener. |
Beta Was this translation helpful? Give feedback.
You are starting the stream prematurely by registering the data listener. Call pause after registering the listener.