adafruit / adafruit/Adafruit_CircuitPython_Requests

File uploads and chunked Transfer-Encoding

Open
#141 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
49
Forks
39
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository files, tests, or entry points are named. Start by reading related issue #89 and the linked Python requests streaming-uploads documentation, then determine the project’s intended scope for file uploads and chunked Transfer-Encoding; done should be demonstrated by sending camera data without buffering it to storage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.