Alex BourgOriginal post
Quality
I am trying to upload file to appwrite storage, but it's not working, I tried with the 2 following codes:
Code1: using InputFile:
JavaScript
const { Client, Storage, InputFile } = require('node-appwrite');const filePath = './path/to/your/file.txt'; // Local file pathconst 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:
JavaScript
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
Summary
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.