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

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

Merged
merged 3 commits into from
May 6, 2024
Merged

Conversation

brc-dd
Copy link
Member

@brc-dd brc-dd commented Apr 24, 2024

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

TODO

  • update docs

@brc-dd brc-dd requested a review from kiaking as a code owner April 24, 2024 10:11
Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for sefirot-story ready!

Name Link
🔨 Latest commit be296dc
🔍 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.

Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for sefirot-docs ready!

Name Link
🔨 Latest commit be296dc
🔍 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.

lib/http/Http.ts Outdated Show resolved Hide resolved
@brc-dd brc-dd changed the title feat(api): add postOrUpload method to send JSON as string in formDataKey feat(http): add postOrUpload method to send JSON as string in formDataKey Apr 24, 2024
@brc-dd brc-dd force-pushed the json-in-formdata branch 2 times, most recently from 9d2b012 to d6bd2bb Compare April 24, 2024 12:21
@brc-dd brc-dd changed the title feat(http): add postOrUpload method to send JSON as string in formDataKey feat(http): support sending json along with files Apr 24, 2024
@brc-dd brc-dd changed the title feat(http): support sending json along with files feat(http): support sending files along with json Apr 24, 2024
@brc-dd brc-dd self-assigned this Apr 24, 2024
@kiaking
Copy link
Member

kiaking commented Apr 25, 2024

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
Copy link
Member Author

brc-dd commented Apr 25, 2024

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
Copy link
Member

kiaking commented Apr 25, 2024

Gotcha! Make sense 👍

kiaking
kiaking previously approved these changes Apr 25, 2024
Copy link
Member

@kiaking kiaking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Please merge and release whenever you're ready.

@brc-dd brc-dd added the enhancement New feature or request label Apr 26, 2024
@brc-dd brc-dd merged commit dd75beb into main May 6, 2024
4 of 5 checks passed
@brc-dd brc-dd deleted the json-in-formdata branch May 6, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants