Back

upload file to storage

  • 0
  • Web
Alex Bourg
19 Aug, 2024, 17:11

I am trying to upload file to appwrite storage, but it's not working, I tried with the 2 following codes:

Code1: using InputFile:

TypeScript
const { Client, Storage, InputFile } = require('node-appwrite');
const filePath = './path/to/your/file.txt'; // Local file path
const fileName = 'uploaded-file.txt'; // Name to assign to the file in Appwrite

const file = InputFile.fromPath(filePath, fileName);

const fileUploadResponse = await storage.createFile(
    process.env.APPWRITE_STORAGE_QRCODES,
    'unique()',
    file
);

Code2: using createReadStream:

TypeScript
const { Client, Storage, InputFile } = require('node-appwrite');
const file = fs.createReadStream(qrCodeFilePath);
const fileUploadResponse = await storage.createFile(
    process.env.APPWRITE_STORAGE_QRCODES,
    'unique()',
    file
);

related issue: https://appwrite.io/threads/1250841985699287143

TL;DR
Developers are struggling to upload a file to appwrite storage. Solution: The issue could be due to improper implementation of `InputFile` or `createReadStream`. Ensure the file path and format are correct. Also, refer to the `createFile` method in the storage API reference docs for guidance: https://appwrite.io/docs/references/cloud/server-nodejs/storage#createFile.
choir24 (Richard)
19 Aug, 2024, 17:26

Can I ask what error messages you are receiving? Also, have you taken a look at the storage api reference docs for createFile? https://appwrite.io/docs/references/cloud/server-nodejs/storage#createFile

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