I have large images that I need to download
from 1 URL and then upload to another. To make the app scalable with large number of large images, I’d like to stream
these rather than downloading+uploading.
I tried this (as you can see with both axios and fetch):
<code>const uploadImage = async (srcUrl, targetUrl) => {
const response = await fetch(srcUrl);
const reader = response.body.getReader();
await axios({
method: 'put',
url: targetUrl,
data: reader,
});
// await fetch(targetUrl, {
// method: 'PUT',
// body: reader,
// });
}
</code>
<code>const uploadImage = async (srcUrl, targetUrl) => {
const response = await fetch(srcUrl);
const reader = response.body.getReader();
await axios({
method: 'put',
url: targetUrl,
data: reader,
});
// await fetch(targetUrl, {
// method: 'PUT',
// body: reader,
// });
}
</code>
const uploadImage = async (srcUrl, targetUrl) => {
const response = await fetch(srcUrl);
const reader = response.body.getReader();
await axios({
method: 'put',
url: targetUrl,
data: reader,
});
// await fetch(targetUrl, {
// method: 'PUT',
// body: reader,
// });
}
However, this doesn’t seem to work. All images
uploaded this way are text files:
<code>{}
</code>
<code>{}
</code>
{}
Adding { mode: "byob" }
to the reader results in an error:
<code>error: TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stream' must be a byte stream. Received ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
</code>
<code>error: TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stream' must be a byte stream. Received ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
</code>
error: TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stream' must be a byte stream. Received ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
Anyone has done this before? I’d appreciate help.