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

Check array fields normalizations when converting to multipart/form-data #274

Closed
ganigeorgiev opened this issue Jan 14, 2024 · 1 comment

Comments

@ganigeorgiev
Copy link
Member

Related to pocketbase/pocketbase#4150.

@ganigeorgiev
Copy link
Member Author

ganigeorgiev commented Jan 14, 2024

A partial fix was implemented in master.

The "fix" is partial because there are still 2 edge cases that are not handled - when a json field value is empty array (eg. []) or array of strings (eg. ["a","b"]).

The reason for this is because the SDK doesn't have information about the field types and doesn't know which field is a json or an arrayable select, file or relation, so it can't serialize it properly on its own as FormData string value.

If you are having troubles with persisting json values as part of a multipart/form-data request the easiest fix for now is to manually stringify the json field value:

await pb.collection("example").create({
  // having a Blob/File as object value will convert the request to multipart/form-data
  "someFileField": new Blob([123]),
  "someJsonField": JSON.stringify(["a","b","c"]),
})

A proper fix for this will be implemented with PocketBase v0.21.0 where we'll have support for a special @jsonPayload multipart body key, which will allow us to submit mixed multipart/form-data content (kindof similar to the multipart/mixed MIME).

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