Repository navigation
Closed
Description
This is how I'm using the library, and for this case it works fine. It creates a new file with a random suffix.
const asset: Asset = await assetsService.upload({
file: imageBuffer,
fileName: "avatar.jpeg",
folder: "/avatars",
}).catch(e=> {
Logger.error(e);
});But I want to replace the existing file when a new file of the same name is uploaded. So, I tried used the useUniqueFileName option and set it to false. But whenever the useUniqueFileName is set, the library throws the following error:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer. Received type boolean (false)
at write_ (_http_outgoing.js:653:11)
at ClientRequest.write (_http_outgoing.js:621:15)
at Request.write (/app/node_modules/request/request.js:1494:27)
at FormData.ondata (internal/streams/legacy.js:19:31)
at FormData.emit (events.js:315:20)
at FormData.CombinedStream.write (/app/node_modules/combined-stream/lib/combined_stream.js:138:8)
at FormData.CombinedStream._pipeNext (/app/node_modules/combined-stream/lib/combined_stream.js:126:8)
at FormData.CombinedStream._realGetNext (/app/node_modules/combined-stream/lib/combined_stream.js:99:10)
at FormData.CombinedStream._getNext (/app/node_modules/combined-stream/lib/combined_stream.js:82:12)
at FormData.CombinedStream.resume (/app/node_modules/combined-stream/lib/combined_stream.js:154:10)
at FormData.CombinedStream.pipe (/app/node_modules/combined-stream/lib/combined_stream.js:66:8)
at end (/app/node_modules/request/request.js:533:22)
at FormData.<anonymous> (/app/node_modules/request/request.js:575:9)
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
code: 'ERR_INVALID_ARG_TYPE'
}The same error is thrown even if useUniqueFileName is set to true:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer. Received type boolean (true)
at write_ (_http_outgoing.js:653:11)
at ClientRequest.write (_http_outgoing.js:621:15)
at Request.write (/app/node_modules/request/request.js:1494:27)
at FormData.ondata (internal/streams/legacy.js:19:31)
at FormData.emit (events.js:315:20)
at FormData.CombinedStream.write (/app/node_modules/combined-stream/lib/combined_stream.js:138:8)
at FormData.CombinedStream._pipeNext (/app/node_modules/combined-stream/lib/combined_stream.js:126:8)
at FormData.CombinedStream._realGetNext (/app/node_modules/combined-stream/lib/combined_stream.js:99:10)
at FormData.CombinedStream._getNext (/app/node_modules/combined-stream/lib/combined_stream.js:82:12)
at FormData.CombinedStream.resume (/app/node_modules/combined-stream/lib/combined_stream.js:154:10)
at FormData.CombinedStream.pipe (/app/node_modules/combined-stream/lib/combined_stream.js:66:8)
at end (/app/node_modules/request/request.js:533:22)
at FormData.<anonymous> (/app/node_modules/request/request.js:575:9)
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
code: 'ERR_INVALID_ARG_TYPE'
}Metadata
Metadata
Assignees
Labels
No labels
Activity
imagekitio commentedon Jul 23, 2020
@k3rn31p4nic
For now, can you pass the value as string type e.g.
useUniqueFileName: "false"We will fix this issue soon.
iamtraction commentedon Jul 23, 2020
Yeah, I'm doing that as a workaround after looking at the code. The data is being sent as a formdata object, so, the
requestlibrary isn't serializing boolean (or any non-string/buffer data type, for that matter) for it to work. Maybe you can serialize the arguments in the library itself before sending it torequest.Anyways, thanks. Found this service recently and been implementing it in one of my apps instead of S3.
imagekitio commentedon Aug 21, 2020
This has been fixed in version 3.1.0