Back

Issues using node-appwrite for uploading files to storage bucket

  • 0
  • Self Hosted
  • Storage
  • Cloud
Franco van Vuuren(u21463702)
3 Sep, 2023, 17:29
TypeScript
async function uploadPdfToBucket(pdfBuffer, customFilename) {
  try {
    const bufferStream = new stream.PassThrough();
    bufferStream.end(pdfBuffer);
    // Upload the file to your Appwrite bucket
    storage.createFile('...', 'test1', bufferStream);
  }catch (error) {
    throw error;
  }
}

I have the above function that takes in a pdfBuffer to upload to my storage bucket. I get the following error while running the code:

TypeScript
            file.stream.pipe(writeStream);
                        ^
TypeError: Cannot read properties of undefined (reading 'pipe')
    at C:\Users\franc\Desktop\test\node_modules\node-appwrite\lib\services\storage.js:455:25
    at new Promise (<anonymous>)
    at Storage.createFile (C:\Users\franc\Desktop\test\node_modules\node-appwrite\lib\services\storage.js:393:22)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Note: I did not use the bufferStream, like the docs suggest, before and still received the same error.

Also I think there might be some mistakes in the example code for the docs:

TypeScript
const sdk = require('node-appwrite');
const fs = require('fs');

// Init SDK
const client = new sdk.Client();

const storage = new sdk.Storage(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;

const promise = storage.createFile('[BUCKET_ID]', '[FILE_ID]', InputFile.fromPath('/path/to/file.png', 'file.png'));

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

--the import fs is never used --and as is InputFile is not recognized

TL;DR
Issue: The user is facing an error while using node-appwrite to upload files to a storage bucket. The error message states that there is a "TypeError: Cannot read properties of undefined (reading 'pipe')". The user suspects there might be mistakes in the example code provided in the docs, specifically regarding the use of bufferStream and InputFile. Solution: The user should modify their code to use bufferStream properly before uploading the file. Additionally, they should import InputFile from the sdk and use it in their code as shown in the example code provided in the docs.
Drake
3 Sep, 2023, 20:27

It should be sdk.InputFile

Drake
3 Sep, 2023, 20:28

Can you create a GitHub issue for the docs problem so we don't forget about it?

Franco van Vuuren(u21463702)
3 Sep, 2023, 20:30

Thanks for the response. Will create an issue in the morning.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more