Separating serialization from content type

Is there a way in httpPut to separate how it serializes data from the Content-Type header set in the request? I'm trying to upload an image file (still from security camera) to Azure storage for use in a cloud dashboard. To make the image render properly in a browser I should set the content type to image/jpeg on the PUT. In that case I got an error about not knowing how to send the data. If I upload it as application/octet-stream the upload succeeds. However, the file type is then wrong. Is there a way I can say to serialize as binary yet let me control what the resulting Content-Type header in the request is. My fallback is to always modify the content type after the fact. I'd prefer to avoid the race condition since that allows a window after every upload where the content type is wrong.

I would try sending it as a base64 encoded string with the content type set appropriately so that the client knows how to interpret it. Do you also control the code on the receiving side?

Thanks for the suggestion. Had time to get back to this and realized the Azure storage API has a custom header to control what content type is stored for the uploaded file. That way I could let the httpPut content type be octet-stream but have the correct image/jpeg on the uploaded file.

ex: x-ms-blob-content-type: image/jpeg.

Once I cleanup the driver code will share it. Allows me to have a cloud dashboard that can show a snapshot from my security cameras which are only directly accessible locally.

1 Like