globalbrain / sefirot

Global Brain Design System.
https://sefirot.globalbrains.com
MIT License
151 stars 12 forks source link

feat(http): support sending files along with json #522

Closed brc-dd closed 2 months ago

brc-dd commented 2 months ago

don't merge yet, I'll test it out first

TODO

netlify[bot] commented 2 months ago

Deploy Preview for sefirot-story ready!

Name Link
Latest commit be296dc08383dd1b82e6e15581917bf137e7c7c6
Latest deploy log https://app.netlify.com/sites/sefirot-story/deploys/663945d14c73770008665251
Deploy Preview https://deploy-preview-522--sefirot-story.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 2 months ago

Deploy Preview for sefirot-docs ready!

Name Link
Latest commit be296dc08383dd1b82e6e15581917bf137e7c7c6
Latest deploy log https://app.netlify.com/sites/sefirot-docs/deploys/663945d14c73770008665253
Deploy Preview https://deploy-preview-522--sefirot-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

kiaking commented 2 months ago

Ahah. OK let me know if I'm understanding the code here.

So, when we use post method and pass in FormData (usually containing file), then it will create this stringified json data. And When upload is used, it will append non binary data just as key-value to the formdata...?

brc-dd commented 2 months ago

upload is not changed. upload is called with body like { foo: File, bar: 1 }, then corresponding form data will have foo = File and bar = '1' and will be sent using POST request.

If post is called with body like { foo: File, bar: 1 }, then corresponding form data will have foo = File and __payload__ = '{"bar":1}' and will be sent using POST request.

If post is called with body not containing any File, then normal JSON POST request will be sent instead of multipart one. (same as earlier)

upload is effectively redundant after this PR if the backend has the middleware to parse __payload__

kiaking commented 2 months ago

Gotcha! Make sense 👍