parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.92k stars 4.78k forks source link

Specify where a file should be uploaded #8731

Open Meglali20 opened 1 year ago

Meglali20 commented 1 year ago

New Feature / Enhancement Checklist

Current Limitation

When trying to upload a file using parse-server-fs-adapter, if you try to specify the folder where a file should be uploaded (for example: folder1.ext) there is an issue where parse server would not allow the the post request.

Feature / Enhancement Description

Add a config option that would specify the files structure, and what subfolders are allowed to be used.

Example Use Case

uploading a file named file1.ext works but when specifying the folder to where to upload the files such as folder1/file1.ext won't work, same as described in this issue https://github.com/parse-community/parse-server-s3-adapter/issues/16

Alternatives / Workarounds

3rd Party References

parse-github-assistant[bot] commented 1 year ago

Thanks for opening this issue!

mtrezza commented 1 year ago

From the related discussions (https://github.com/parse-community/parse-server-s3-adapter/issues/16 and linked), it seems that Parse Server has been prepared to handle directories by allowing the filename to be a path (https://github.com/parse-community/Parse-Swift/issues/417#issuecomment-1250171330), but it depends on the adapter to be able to handle the path. So this issue may belong to parse-server-fs-adapter (you don't have to open a new one, we can transfer this issue if needed).

The S3 adapter PRs for this could be a first guideline for implementing this in the FS adapter. We'd be happy to review a PR if you want to give it a try.

Meglali20 commented 1 year ago

I see that in ((https://github.com/parse-community/Parse-Swift/issues/417#issuecomment-1250171330)) There is a workaround by separating the folder and the filename with "%2F" instead of "/", if you use "/" parse server don't allow the request to be made and returns a POST error instead. I did try to make changes to the FS adapter but the call to the adapter wasn't reached because the POST error occurred before that. A proper solution from the server side could be implemented with additional features such as who is authorized to upload to specific folders and that also would be mentioned in the parse documentation. Also keep in mind that if you set the option preserveFileName to false, the filename might become too long.

mtrezza commented 1 year ago

Got it;

Meglali20 commented 1 year ago

Adding this to the parse server side would also make it possible to handle directory permissions, such as making a directory accept uploads only and not serving files or the opposite. or even add the option of which directories to encrypt files for example an app that has public posts the files wouldn't be encrypted but the files shared via a chat can be encrypted.