Back

Files from buckets, not accessable?

  • 0
  • Self Hosted
  • Web
Camo
8 Feb, 2024, 20:15

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.

TypeScript
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
TL;DR
Developers are asking for help with accessing files from buckets in Appwrite. They are asking if there's a way to add new functions without rewriting the content and templates. They also mention having issues with downloading files and not having the correct permissions. They provide a code snippet that seems to generate the correct link, but it's not working in terms of permissions. Solution: The support team can check the request headers from the browser network logs to see if the cookie is there. They can also check if changing the read permission to "any" allows the user to download the file.
Camo
8 Feb, 2024, 20:16

{"message":"The requested file could not be found.","code":404,"type":"storage_file_not_found","version":"1.4.13"}

Camo
8 Feb, 2024, 20:16

the bucket id is right, the permissions on the file are right, the project id is right

Camo
8 Feb, 2024, 20:17

and the same user, can't download the file

Steven
8 Feb, 2024, 20:17

what happens if you change read permission to any?

Camo
8 Feb, 2024, 20:17

hold on

Camo
8 Feb, 2024, 20:18

yea then i got a link and it downloads

Steven
8 Feb, 2024, 20:19

can you check the request headers from the browser network logs? is the cookie there? or maybe there's a separate cookie tab

Camo
8 Feb, 2024, 20:19

hold on

Camo
8 Feb, 2024, 20:21

ok it seems it was a browser problem, obv the site was open in incognito and i was trying to download from other tab

Camo
8 Feb, 2024, 20:21

jesus

Camo
8 Feb, 2024, 20:22

4 browsers open, stuff happens, i'm sorry it's my bad

Steven
8 Feb, 2024, 20:22

no worries! it happens!

Camo
8 Feb, 2024, 20:22

atleast i'm happy that the security side works perfectly

Camo
8 Feb, 2024, 20:22

really pleased

Camo
8 Feb, 2024, 20:24

@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

Camo
8 Feb, 2024, 20:24

probbably i dont, but if you know a better way, please advise

Camo
8 Feb, 2024, 20:25

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

Steven
8 Feb, 2024, 20:25

what do you mean?

Steven
8 Feb, 2024, 20:25

make a new function i create a template

Steven
8 Feb, 2024, 20:25

?

Camo
8 Feb, 2024, 20:26

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/

Camo
8 Feb, 2024, 20:26

then i have to pull, and write the functions inside of the template that was downloaded, nothing fancy, but i was wondering

Camo
8 Feb, 2024, 20:27

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 ?

Steven
8 Feb, 2024, 20:54

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?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more