Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to pass additional parameters to backend when saving/uploading file #1201

Open
3 tasks done
evtimDev opened this issue Oct 27, 2023 · 1 comment
Open
3 tasks done

Comments

@evtimDev
Copy link

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:

  1. Client needs to upload a file and update an object field with the file
  2. Client calls file.saveInBackgroundWithParams(<JSON with parseClass, objectId and filed>)
  3. 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:

  1. 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.

  2. 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

@parse-github-assistant
Copy link

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant