You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when we call file.saveInBackground(), etc. we can't pass any additional parameters to be sent together with the POST request to the backend for the server-side code to examine/act upon.
Feature / Enhancement Description
Let's add a version of file.saveInBackground() with additional JSON params to be send with the file POST request to the server-side.
Example Use Case
Server-side association of file with database object:
Client needs to upload a file and update an object field with the file
Client calls file.saveInBackgroundWithParams(<JSON with parseClass, objectId and filed>)
On server-side, in Parse.Cloud.afterSaveFile, devs can write custom code that examines the params, perform any validation required, and update the object field with the newly uploaded file as appropriate. If validation fails, the server-side can also delete the file and return appropriate error to client.
The advantage is fewer number of calls to backend, simpler implementation of file validation, simpler bookkeeping and ensuring no unreferenced files get stored.
Alternatives / Workarounds
There are two alternatives currently:
Client makes multiple calls - save file, then another call to update object with saved file. This is less efficient, more error prone and causes potentially multiple copies of the file to be stored in cases where the client retires the file upload operation (if operation succeeded, but client failed to receive response of success for example). Additional work-around to handle those cases would be on the server-side to always create some temporary record for any file saved, then have some sort of background job running with certain interval to delete the files that have not been associated in reasonable time.
New Feature / Enhancement Checklist
Current Limitation
Currently, when we call file.saveInBackground(), etc. we can't pass any additional parameters to be sent together with the POST request to the backend for the server-side code to examine/act upon.
Feature / Enhancement Description
Let's add a version of file.saveInBackground() with additional JSON params to be send with the file POST request to the server-side.
Example Use Case
Server-side association of file with database object:
The advantage is fewer number of calls to backend, simpler implementation of file validation, simpler bookkeeping and ensuring no unreferenced files get stored.
Alternatives / Workarounds
There are two alternatives currently:
Client makes multiple calls - save file, then another call to update object with saved file. This is less efficient, more error prone and causes potentially multiple copies of the file to be stored in cases where the client retires the file upload operation (if operation succeeded, but client failed to receive response of success for example). Additional work-around to handle those cases would be on the server-side to always create some temporary record for any file saved, then have some sort of background job running with certain interval to delete the files that have not been associated in reasonable time.
Using REST API to implement custom file POST request with params passed in either as additional header, or following the JS SDK example, leveraging the metadata/tags format, see How to send metadata when using restful api to upload a image? parse-server#6771
3rd Party References
This is somewhat similar to the JS Parse SDK File.addMetadata(), https://docs.parseplatform.org/js/guide/#adding-metadata-and-tags
The text was updated successfully, but these errors were encountered: