How do you parse a file posted to a HTTP Trigger
ksaye opened this issue · 4 comments
When posting a file to an Azure Function running Python, how can I get access to the binary file?
Using the command "request = open(os.environ['req'], encoding='utf8').read()" I see the following.
How can I get the file back into a binary file so I can work with it?
contents of the req file:
--------------------------75f5275367eceed8
Content-Disposition: form-data; name="file"; filename="2018-11-02-12-59-58.wav"
Content-Type: application/octet-stream
RIFF�( WAVEfmt � � � D� ��� � � data�_( ��������ëëͫͫثث������������������!�!�,�,�6�6�A�A�K�K�V�V�
�`�k�k�u�u�����������������������������ɬɬӬӬ
����h���
��������
��t
�
|�
c���
--------------------------75f5275367eceed8
Content-Disposition: form-data; name="output"
json
--------------------------75f5275367eceed8--
@ksaye
Can you please read this and let me know how it will work for you.
Azure/azure-functions-host#2009
Thanks for the reference. Later I realized that the file created "os.environ['req']" was almost 2x the size.
Based on comments from Liang, I decided to change approach.
- (client side) upload the file to Azure Blob Storage
- (client side) post the Blob URL to the Python Azure Function
- (Function Side) process the URL and calculate the needed score (Tensorflow)
- (function Side) return the score to step 2 above connection as a JSON message
- (client side) take action based on the score
This also gave me the ability to collect the files cloud side to building better models.
I would have liked to avoided the Blob Post, but this was just a few lines of extra code.
(Thanks Liang for the suggestion)
K
Closing this issue. Please feel free to open if needed