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
- Function deployment failed: Unable to re...
Hi Appwrite team, I have been experiencing persistent errors when i attempt to push my appwrite functions. The logs on the deployment detail page on the console...
- Github connection error - Self Hosted Ap...
I am trying to connect my github account to deploy a project to sites, but Connect to Gtihub button is disabled. I have configured all Env variables needed for...
- "Domain verification failed"
"Domain verification failed" I was install Appwrite in my VDS server. I using Coolify for install Appwrite. After install complete, i want add my domain, and i ...