Issue with posting image to prusa connect image API.
I recently recieved my Prusa XL and things have been working well. I ordered a usb camera to use with a raspberry pi 0 w. I was unable to find a script that handled this yet so I decided to write my own. The issue I am having is that the image sent to the API looks like the following:
This has lead me to believe that my encoding is wrong but I am not sure how to correct this. I also have been unable to find anything like this on the forum. I have attempted not sending a byte string and instead sending the raw image but that did not work either My source code is below and I am currently testing said code on my laptop before deploying it to a raspberry pi. Has anyone else encountered this issue or have suggestions? .
import base64 import httpx import cv2 import numpy import requests cap = cv2.VideoCapture(1) HTTP_URL = "https://webcam.connect.prusa3d.com/c/snapshot" FINGERPRINT = TOKEN = result, image = cap.read(cv2.CAP_FFMPEG) headers = { 'Content-Type': 'image/jpg', 'fingerprint': FINGERPRINT, 'token': TOKEN, } def upload_image(http_url, fingerprint, token, image): _, img_encoded = cv2.imencode(".jpeg", image) response = requests.put( http_url, headers={ "content-type": "image/jpg", "fingerprint": fingerprint, "token": token, }, data=img_encoded.tobytes(), ) return response image = cv2.resize(image, (640, 480)) #with httpx.Client() as client: # response = client.put(url=HTTP_URL, headers=headers, content=cv2.imencode(".jpeg", image)[1].tobytes()) response = upload_image(HTTP_URL, FINGERPRINT, TOKEN, image) print("this is the request " + response.text)
RE: Issue with posting image to prusa connect image API.
Wow! No body else is trying to upload camera images? I find that hard to believe. With the latest version of `rpicam-still` I get the error JSON `{"detail": "Invalid snapshot type"}` Nice. That's not listed as a possible error from the Camera API `upload` method Not great API documentation. It would be _really_ nice if the API just said something like, "The snapshot needs to be no more than this wide, this aspect ratio, this size, ..." Anything helpful really would be better than this error message.
RE:
Been doing that for a long time, no issues.
https://github.com/nvtkaszpir/prusa-connect-camera-script
Maybe I was lucky enough not to have cameras with anything higher than 2k resolution?
See my GitHub and printables.com for some 3d stuff that you may like.
RE: Issue with posting image to prusa connect image API.
Just to close the loop here. While I still don't love the error diagnostics from the API, the upload problem was my own. I was using the `curl` command from my program, the same as the `prusa-connect-camera-script` and I forgot to add the `@` sign in front of the file name. Curl doesn't bother warning you when you do that, even though results in nothing being uploaded. So all is well and I have camera snapshots.