0

I am trying transfer a file to Stripe from a firebase database using the stripe.File.create() method. Here is the code that I am using:

file_url = storage.child("/path/to/file").get_url(token=None)
response = requests.get(file_url, stream=True)
    img = Image.open(BytesIO(response.content))
    stripe.File.create(
        purpose="identity_document",
        file=img
    )

But when I run this code I get:

Request req_E7fskNVgpHHlRm: Invalid hash

I believe I am getting the correct image from firebase, since I can run the following line and get the image saved to my local drive:

img.save("test.jpg")

But Stripe doest not seem to like the file format that I am giving it. I believe the file has to be supplied in binary mode, so perhaps I simply need to do edit the line img = Image.open(BytesIO(response.content)) to get the file in binary mode.

Any feedback is appreciated.

Brian L
  • 549
  • 7
  • 21
  • Are you setting the correct MIME type when sending the file? Have a look at https://stripe.com/docs/file-upload#uploading-a-file – Paul Asjes May 21 '19 at 04:37
  • How do you specify the MIME type? Is that in the header of the file? I can save as a .jpg. The documentation does not show how to set the correct MIME type – Brian L May 21 '19 at 20:40

1 Answers1

0

I figured it out. img = Image.open(BytesIO(response.content)) creates a JpegImageFile object, which is an image. But Stripe is expecting a file, something like io.BufferedReader object. So Stripe is saying that you are supplying an image, when really it just wants a file. To fix the issue, just change the img = line to:

imgFile = BytesIO(response.content)
Brian L
  • 549
  • 7
  • 21