Rank 4: Virtual Machine
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