After user uploading a file, i got an event that looks up that buckets upload events. I catch the file and create the url. Its not accessable by that user.
import { Client, Storage } from 'node-appwrite';
export default async ({ req, res, log, error }) => {
const client = new Client()
.setEndpoint(process.env.APPWRITE_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY);
const storage = new Storage(client);
const { body, headers, method, url, path } = req;
const { $id, bucketId, name, mimeType, sizeOriginal } = body;
const { 'x-appwrite-user-id': userId } = headers;
const { host, scheme, port, query, queryString } = url;
const { connection, contentLength, contentType, host: hostHeader, useragent } = headers;
const { $createdAt, $updatedAt, $permissions, signature, chunksTotal, chunksUploaded } = body;
log(`${$createdAt} User: ${userId} uploaded a file in bucket ${bucketId}, called ${name} ${mimeType} ${sizeOriginal}, that has the id now of ${$id}`)
log(`${hostHeader} - ${useragent}`)
log(`${process.env.APPWRITE_ENDPOINT}/storage/buckets/${bucketId}/files/${$id}/download?project=${process.env.APPWRITE_FUNCTION_PROJECT_ID}`)
return res.json({
});
};``` seems correct way to make the link but its not working in terms of permissions
{"message":"The requested file could not be found.","code":404,"type":"storage_file_not_found","version":"1.4.13"}
the bucket id is right, the permissions on the file are right, the project id is right
and the same user, can't download the file
what happens if you change read permission to any?
hold on
yea then i got a link and it downloads
can you check the request headers from the browser network logs? is the cookie there? or maybe there's a separate cookie tab
hold on
ok it seems it was a browser problem, obv the site was open in incognito and i was trying to download from other tab
jesus
4 browsers open, stuff happens, i'm sorry it's my bad
no worries! it happens!
atleast i'm happy that the security side works perfectly
really pleased
@Steven i got one not related question, its more workflow question, i got functions now added to my sites github account, and to make a new function i create a template and store in the /appwrite-functions/new-function-name/ folder, i 'm currious if there is a way for me to make the function locally, and add it somehow to the appwrite, because atm created from template, syncing, then rewriting seems a bit of overead, maybe i just don't know something
probbably i dont, but if you know a better way, please advise
it's not hard, just takes extra 5 minutes to make this way, but wen you are in the zone, it's mentally challanging to step back from the building, if you know what i mean
what do you mean?
make a new function i create a template
?
well, look, i got two functions now in my github account, that i've added to the repo as templates and just wrote the folder structure e.g. /appwrite-functions/after-upload/
then i have to pull, and write the functions inside of the template that was downloaded, nothing fancy, but i was wondering
if i write a function offline, as i'm on a boat for weeks of time, and maybe there is a way to add the new functions by not adding them as template and rewriting the content ?
not adding them as template and rewriting the content
You mean not copying and pasting an existing function and updating it to be your new function?
Recommended threads
- Error When load the website
Hi, I am getting this error whenever I reload my website please help me, I am using react Error: ** GET https://cloud.appwrite.io/v1/account 401 (Unauthoriz...
- Migrate from cloud to localhost
Hello everyone. I need to migrate my test project from cloud to localhost, however it seems that this is possible only if a self-hosted appwrite instance it's h...
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?