ERROR in Sending file buffer to client.upload

I’m using @spheron/storage SDK form node.js express app trying to upload a file as buffer.
Error uploading file: TypeError [ERR_INVALID_ARG_VALUE]: The argument ‘path’ must be a string or Uint8Array without null bytes. Received <Buffer 1f 8b 08 00 15 dc b4 64 00 03 ec 3b 67 6f e3 48 96 fd 79 81 fd 0f 46 03 f7 49 2b 33 88 a4 c8 01 66 b0 a2 12 95 b3 44 f2 …

code snippet

	const { uploadId, bucketId, protocolLink, dynamicLinks } =
		// await client.upload("C:\\Users\\developer\\Desktop\\data.txt", {
		await client.upload(buffer, {
			protocol: ProtocolEnum.IPFS,
			onUploadInitiated: (uploadId) => {
				console.log(`Upload with id ${uploadId} started...`);
			onChunkUploaded: (uploadedSize, totalSize) => {
				currentlyUploaded += uploadedSize;
				console.log(`Uploaded ${currentlyUploaded} of ${totalSize} Bytes.`);

@rekpero @Shomix can you please take a look & provide your help please.

I think you can convert your Buffer value to UInt8Array and then pass it to the client.upload(...) method. Here is how you can do it:

To convert a buffer to a Uint8Array, you can use the Uint8Array constructor directly since Node.js Buffers are built on top of the ArrayBuffer. Here’s a simple way to do it:

function bufferToUint8Array(buffer) {
    return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);

// Example usage:
const buffer = Buffer.from([1, 2, 3, 4, 5]);
const uint8array = bufferToUint8Array(buffer);
console.log(uint8array);  // Uint8Array(5) [ 1, 2, 3, 4, 5 ]

This will create a new view (the Uint8Array) on the same underlying memory as the buffer, so modifications to the Uint8Array will affect the original buffer and vice versa.

It is not possible to upload the file as a buffer.

The upload function takes the path parameter that points to the location of the file ( or directory ) that will be uploaded.

Did you try with providing the file path instead of a buffer?

1 Like

Working if it’s a file path