I want to use the WebODM API to stream images from one remote location to the other. It has to work chunk by chunk to prevent lots of memory problems, and to be able to pick up a partial upload if for some reason connections are broken.
I found this post, that also has a similar use case. Apparently there is a “partial”: True option that I can pass along, but I couldn’t get that to work. I now tried the following code piece.
for n, img in enumerate(imgs):
c = s.get("file://" + img, stream=True).content
images[n] = ('images', (os.path.split(img)[-1], c, 'image/jpg'))
if n > 0:
images[n-1] = ('images', (images[n-1][1], None, 'image/jpg'))
offset = index + len(c)
if n < len(imgs)-1:
length = offset
partial = True
else:
length = offset - 1
partial = False
headers["Content-Range"] = f'bytes {index}-{offset-1}/{length}'
url = f"{odmconfig.host}:{odmconfig.port}/api/projects/{project_id}/tasks/"
res = requests.post(
url,
files=images,
headers=headers,
data={
'options': options,
'partial': partial,
}
)
index = offset
As you can see, I am testing with a stream of quasi-remote files. This leads to one task being created for each post, with a uuid for each. each task holds zero photos. So my questions are:
How do you create only one unique task in this manner?
What is the appropriate way to upload one chunk of data to an existing task as partial upload?
How do you notify in the post that uploads are done and the task can be executed?
Thanks!
Thanks a lot! I have some progress. The partial task creation works as expected. Now I am using requests to get a post with a single image in place. I have done this as follows, the variable ‘c’ contains the binary data of the image.
I have also tried this with files=images instead of data = {images}. The upload route is definitely reached but the request.FILES part remains empty. I receive a response back saying that there are not files.
It is probably an obvious thing. What am I doing wrong? Thanks for the help.
Sorry, perhaps my example threw you off (the content-type was just an example, with xxxxxxxx being a placeholder), but you’re not using requests properly. You probably want to use requests-toolbelt · PyPI to make multipart form uploads.