maciejtreder / serverless-apigw-binary

Serverless plugin for binary files support in AWS Gateway
MIT License
160 stars 33 forks source link

how to accept a binary file #41

Open amitm02 opened 6 years ago

amitm02 commented 6 years ago

I'm attempting to crate a lambda function in python that accepts an image file via a POST request. I've managed to config your plugin to my serverless service, and indeed i can see in the console the api gateway accepts image/png. However, I failed to understand how i can access the image data in the lambda.

Should it be in "event['body']"? Is it Base64Encoded?

trying to decode it i get:

[INFO]  2018-01-08T11:32:42.54Z 9c53dd3c-f467-11e7-832c-a9255a9beabd    API isBase64Encoded=False
[INFO]  2018-01-08T11:32:42.54Z 9c53dd3c-f467-11e7-832c-a9255a9beabd    body type=<class 'str'>
[INFO]  2018-01-08T11:32:42.54Z 9c53dd3c-f467-11e7-832c-a9255a9beabd    body len: 400582
[INFO]  2018-01-08T11:32:42.54Z 9c53dd3c-f467-11e7-832c-a9255a9beabd    content-type: multipart/form-data; boundary=--------------------------913555983037172620420628
[INFO]  2018-01-08T11:32:42.54Z 9c53dd3c-f467-11e7-832c-a9255a9beabd    b64decoding...
string argument should contain only ASCII characters: ValueError
Traceback (most recent call last):
File "/var/task/ocr.py", line 93, in OCROnUpload
img = b64decode(body)
File "/var/lang/lib/python3.6/base64.py", line 80, in b64decode
s = _bytes_from_decode_data(s)
File "/var/lang/lib/python3.6/base64.py", line 39, in _bytes_from_decode_data
raise ValueError('string argument should contain only ASCII characters')
ValueError: string argument should contain only ASCII characters
juangonzaq commented 5 years ago

Lo pudiste resolver ? tengo el mismo problema :/