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.
TypeScript
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);
}
}
};
TL;DR
Developers are encountering a "failed to fetch" error when trying to download a file from storage within a function due to inability to communicate with other appwrite services. The issue may stem from missing environment variables.Recommended threads
- HUGE OUTRAGE IN APPWRITE, I CANNOT ACCES...
I have 2k users trying to access, sending me messages. What am I supposed to do? Please solve this asap.
- All my apps are not opening now
All my apps are not opening now 200+ apps are not opening plz fast
- Failed to generate functions SSL
```appwrite-worker-certificates | Cannot renew domain (functions.domain.com) on attempt no. 9 certificate: Failed to verify domain DNS records. appwrite-worker...