'download image from google cloud storage and send it in a request fails

I am trying to write a code to first download a dicom image from google cloud storage in python and send it over to a nodejs server in a post request. here is the code snippet

from google.cloud import storage
import requests

storage_client = storage.Client()
bucket = storage_client.bucket("bucket")
blob = bucket.blob("imageaddress.dcm")
dicom = blob.download_as_bytes()
print(len(dicom))


response=requests.post(url='the url', data = dicom,headers={"Accept":"application/octet-stream"})

print(response.text)

The problem is that in nodejs I get this error:"Error "error during parsing dicomParser.ByteStream: parameter byteArray is not of type Uint8Array or Buffer"

I tried the same request in postman and it goes through successfully. I am not sure if python bytes and javascript uint8array are the same format or there has to be some kind of type conversion? I have tried both requests and urllib3 libraries and getting the same result. Any ideas?



Solution 1:[1]

adding

headers={'Content-Type': 'application/octet-stream'}  

as John Hanley said in the comments solved the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zoe stands with Ukraine