Back

Is it possible to upload a file trough a cloud function?

  • 0
  • Functions
  • Storage
memoonlite
2 Feb, 2024, 18:03

Hello everyone! My current code of uploading a file is as follows:

createFile( bucketId: 'id', file: InputFile(), fileId: 'unique()', );

The above code is executed from the client side. The problem here is that an evil person could reverse engineer my code/request and pass anything as fileId. 😈 Such person could do this for example, and the file will end up in my bucket just fine with that modified ID:

createFile( bucketId: 'id', file: InputFile(), fileId: 'TROLLOLOLOL', );

I don't want the client to have any control over what file ID is uploaded. I could use a function that executes by the file upload trigger, but that doesn't change the fact that the file with the modified ID will be in my bucket, even though it’s for a short time.

The best way (I think) to solve this problem would by passing the file to a function and then process it through that same function. My question is: Is it possible to upload a file trough a function and if so, are there any examples of this?

TL;DR
Developers are discussing how to prevent clients from modifying file IDs when uploading files to a cloud function. One suggested approach is to pass the file to a function and process it within that function to ensure control over the file ID. The developer is asking if it is possible to upload a file through a function and if there are any examples available. Solution: One recommended solution is to use a cloud function to handle the file upload. By executing the file upload within the function, developers can have better control over the file ID and prevent clients from manipulating it. Examples or documentation on how to implement this approach are being sought.
Steven
2 Feb, 2024, 18:58

FYI, it's best to wrap multiline with 3 backticks. See: https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

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