
Hello guys,
It's my first function and I'm trying to download a file from my storage and return it but it's not working. The error message is "failed to fetch". The same error occurs when accessing the database so seems that the function is not able to talk with the other appwrite services.
export default async ({ res, req, log, error }: Context) => {
if (!APPWRITE_PROJECT_ID || !APPWRITE_BUCKET_ID || !APPWRITE_API_ENDPOINT || !APPWRITE_API_KEY) {
error(
"Please make sure you have environment variables set.",
);
return;
}
const client = new Client()
.setEndpoint(APPWRITE_API_ENDPOINT) // Your API Endpoint
.setProject(APPWRITE_PROJECT_ID)
.setKey(APPWRITE_API_KEY);
const bucket = new Storage(client);
const fileId = req.path.replace(/^(\/)|(\/)$/g, '');
log("FILE ID: " + fileId);
log("BUCKET ID: " + APPWRITE_BUCKET_ID);
if(req.method === 'GET') {
try {
const file = await bucket.getFileDownload(APPWRITE_BUCKET_ID, fileId);
return res.send(file, 200);
} catch (err) {
error(err.message)
return res.json({ error: err.message }, 500);
}
}
};
Recommended threads
- Explore uploaded images directly from lo...
Is there any option to explore/dwonload uploaded files to from local machine? I connected through WinScp to my vps and to files from docker volume 'appwrite_app...
- Migrate Appwrite
I have appwrite setup in Coolify, where my dev and production both are running on coolify due to upgrade issues and multiple issues when deployed with coolify. ...
- After the new appwrite update, I am havi...
I am having difficulties with Creating and listing documents from appwrite database. It doesn't create the document or list the document from the database altho...
