vaphes / pocketbase

PocketBase client SDK for python
https://pypi.org/project/pocketbase/
MIT License
332 stars 38 forks source link

Switch from JSON to multipart file encoding for file upload #6

Closed m29h closed 1 year ago

m29h commented 1 year ago

File upload is detected when body data contains a value of class FileUpload Remaining non-file-upload is converted to HTTP FormData Entire message is then sent as multipart file transfer. See httpx documentation Supports multiple files upload into a single file field and also supports multiple file fields with different name. solves #5 Example how to use:

r = client.records.create("file_collection", {
    "name": "test123",
    "file_field_a": FileUpload(("first.bin", open("file1.bin", "rb"), "application/octet-stream"), ("second.bin", open("file2.bin", "rb"), "application/octet-stream")),
    "file_field_b": FileUpload(("only_one_file.bin", open("file3.bin", "rb"), "application/octet-stream")),
})
vaphes commented 1 year ago

Hi @m29h , thank you for your submission!