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

File uploads and chunked Transfer-Encoding #141

Open
mycoporium opened this issue Aug 22, 2023 · 1 comment
Open

File uploads and chunked Transfer-Encoding #141

mycoporium opened this issue Aug 22, 2023 · 1 comment

Comments

@mycoporium
Copy link

I am using a TTL serial camera with a board that has no storage, but does have wifi (the M7 metro).

The example code buffers the image from the camera 32 bytes at a time for writing to the SD card. But I was hoping to utilize the Transfer-Enoding: chunked header to send the buffer data with an HTTP request in place of writing to disk.

It doesn't look like the circuitpython requests library supports basic file uploads, let alone a chunked method.

Here is a link to the python-requests docs showing how to do streaming file uploads and chunked body requests: https://requests.readthedocs.io/en/latest/user/advanced/#streaming-uploads

This is a working chunked encoding example that I'm using to test this functionality against a CherryPy server (not shown), which verifies that python-requests can do what it says.

import requests

IMG_FILE = 'image_18000.jpg'

def read_chunks(fileobj, chunk_size=32):

    while True:
        data = fileobj.read(chunk_size)
        if not data:
            break

        yield data

if __name__ == '__main__':

    with open(IMG_FILE, 'rb') as f:
        resp = requests.post('http://hb.local:9001', data=read_chunks(f, 32))

    print(resp.json())

If I have some time, I will try to create a PR for this functionality.

There is also a related issue here: #89

@FoamyGuy
Copy link
Contributor

Basic file uploading is implemented in #189. Contribution of the chunked Transfer-Encoding functionality is welcomed for anyone interested in working on it.

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

2 participants