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
- Having issues with login via CLI
``` ~/appwrite appwrite login --endpoint https://localhost/v1 --verbose ? Enter your email myvalidemai...
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...