#Satyra1
1 messages · Page 1 of 1 (latest)
Hello there
hi
"message": "{\"code\":\"ERR_INVALID_ARG_TYPE\"}",
"stack": "Error: {\"code\":\"ERR_INVALID_ARG_TYPE\"}\n at DiskStorage.filename [as getFilename] (/home/debian/blinkapi/app/src/api/v1/controllers/order/payment.ts:180:12)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"
}```
Hmm that error doesn't seem like it is coming from Stripe?
It is coming from filename, no?
it looks like everything before ```js
const stripefile = await stripe.files.create({
purpose: 'account_requirement',
file: {
data: file,
name: filename,
type: 'application/octet-stream',
},
});
console.log({ stripefile, file });
req.stripeImage = { file: file, stripeFile: stripefile };
}
What is line 180?
if (error) cb(new Error(JSON.stringify(error)), '');
this is correct error message ```js
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
at new NodeError (node:internal/errors:371:5)
at Function.from (node:buffer:322:9)
at push (/home/debian/blinkapi/node_modules/stripe/lib/multipart.js:17:56)
at multipartDataGenerator (/home/debian/blinkapi/node_modules/stripe/lib/multipart.js:39:7)
at Constructor.multipartRequestDataProcessor [as requestDataProcessor] (/home/debian/blinkapi/node_modules/stripe/lib/multipart.js:82:18)
at Constructor._request (/home/debian/blinkapi/node_modules/stripe/lib/StripeResource.js:505:12)
at /home/debian/blinkapi/node_modules/stripe/lib/makeRequest.js:93:10
at new Promise (<anonymous>)
at makeRequest (/home/debian/blinkapi/node_modules/stripe/lib/makeRequest.js:67:10)
at Constructor.create (/home/debian/blinkapi/node_modules/stripe/lib/StripeMethod.js:34:7) {
code: 'ERR_INVALID_ARG_TYPE'
}
Ah okay there we go, thanks
That's helpful
One sec
Seems like it thinks your filename is an object for some reason
Can you log out filename after you build it and also log out typof filename
{ filename: 'stripe_281672256868595.png', type: 'string' }
try {
if (file.fieldname === 'stripeDocumentImage') {
const date = new Date();
filename = 'stripe_' + date.getDate() + date.getTime() + '.png';
console.log({ filename, type: typeof filename });
const stripefile = await stripe.files.create({
purpose: 'account_requirement',
file: {
data: file,
name: filename,
type: 'application/octet-stream',
},
});
console.log({ stripefile, file });
req.stripeImage = { file: file, stripeFile: stripefile };
}
} catch (error: any) {
console.log(error);
if (error) cb(new Error(JSON.stringify(error.message)), '');
}```
Hi there 👋 I'm jumping in as my teammate needs to step away soon.
I see you've added some additional logging, can you confirm exactly which log statements are triggered when you run through the code shown above?
I'm also not seeing how you construct the file variable, can you log the object type for that as well?
ive adeed this logging cuz bismarck ask me to do so
file is data return from multer that contains image from formdata
its type is (parameter) file: Express.Multer.File
The Express.Multer.File type has the following properties:
fieldname: The field name specified in the HTML form
originalname: The name of the file on the user's computer
encoding: The encoding of the file
mimetype: The MIME type of the file
size: The size of the file in bytes
filename: The generated file name for the file in the dest directory
path: The full path to the uploaded file
buffer: A Buffer of the entire file```
{
fieldname: 'stripeDocumentImage',
originalname: 'BX.png',
encoding: '7bit',
mimetype: 'image/png'
}
I think that is the problem. I believe we're trying to read the file's contents, but are receiving a file object instead of a string or a buffer with its contents.
It also looks like the framework you're using includes a buffer on the file object, can you try adjusting this line:
data: file,
to:
data: file.buffer,
and see if that changes the resulting behavior?
i dont know why buffer is undeffined
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
at new NodeError (node:internal/errors:371:5)
at Function.from (node:buffer:322:9)
at push (/home/debian/blinkapi/node_modules/stripe/lib/multipart.js:17:56)
at multipartDataGenerator (/home/debian/blinkapi/node_modules/stripe/lib/multipart.js:39:7)
at Constructor.multipartRequestDataProcessor [as requestDataProcessor] (/home/debian/blinkapi/node_modules/stripe/lib/multipart.js:82:18)
at Constructor._request (/home/debian/blinkapi/node_modules/stripe/lib/StripeResource.js:505:12)
at /home/debian/blinkapi/node_modules/stripe/lib/makeRequest.js:93:10
at new Promise (<anonymous>)
at makeRequest (/home/debian/blinkapi/node_modules/stripe/lib/makeRequest.js:67:10)
at Constructor.create (/home/debian/blinkapi/node_modules/stripe/lib/StripeMethod.js:34:7) {
code: 'ERR_INVALID_ARG_TYPE'
}
I'm not too familiar with the framework that you're using, but based on this SO post and your earlier messages, it looks like you have Multer running in diskStorage mode. It seems this results in the file being written to disk rather than being stored in memory where you can access its buffer:
https://stackoverflow.com/questions/69921812/multer-file-buffer-missing