
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
- Checkout error: Error: Request body is e...
Im absolutely stumped here. ```Initializing Stripe functionality... stripe.ts:74 Calling Appwrite function with payload: {price_id: 'price_1RdZzoDCvcSnLsdCCu8z3...
- Clarification Needed on Custom Domains a...
Hello, I need help configuring custom domains/subdomains in Appwrite: 1. **Current Setup**: - Transferred `mydomain.com` to Appwrite via nameservers ...
- Site don't have Permission?
https://discord.com/channels/564160730845151244/564160731327758347/1386878747902476489 I'm on a self hosted Instance of Appwrite 1.7.4 and getting this error o...
