Here’s my suggestion:
1. Install the fs-files-adapter
, so Parse files are saved to your hard drive.
-
Install the package:
npm install @parse/fs-files-adapter
-
As described in the package’s readme, you just add this to your server’s config file:
{
"appId": 'my_app_id',
"masterKey": 'my_master_key',
// other options
"filesAdapter": {
"module": "@parse/fs-files-adapter",
"options": {
"filesSubDirectory": "my/files/folder", // optional, defaults to ./files
"encryptionKey": "someKey" //optional, but mandatory if you want to encrypt files
}
}
}
2. Upload your files via POST request to Parse’s files endpoint
Make a POST request as described in the guide, just the same way you are currently doing with your cloud function, but instead of sending it to /functions/uploadFile
, you send it to /files/name-of-your-file
curl -X POST \
-H "X-Parse-Application-Id: your-app-id" \
-H "X-Parse-REST-API-Key: your-rest-api-key" \
-H "Content-Type: text/plain" \
-d 'The Content Of Your File' \
https://yourdomain.com/files/hello.txt
With this, you can leverage Parse File’s functionality such as automatic UUID naming and upload progress (not sure how upload progress works with REST though, I haven’t tested it).
Please Note:
If you still want to use a cloud function for whatever reason, then you don’t need any of these and you should proceed just the way you are doing so far.
Let me know if this helps. If not, maybe share more information about your project and what you are trying to achieve.