0

I am trying to extract audio from MIME with no luck. The endpoint is sending to FLASK API, endpoint it's sending Metadata and Audio, I've captured in Wireshark to understand what's being sent. I can extract the Metadata files, if I try to extract the audio I get an audio file with 0bytes. Code and screenshots attached.

Wireshark Trace: Wireshark Trace

Code:

from flask import Flask, request
from flask_restful import Api, Resource
from werkzeug.utils import secure_filename
import json

app = Flask(__name__)
api = Api(app)

class PostMetaAudio(Resource):
    def post(self):
    #This bit WORKS
        m = request.form.get('metadata')
        json_object = json.loads(m)
        guid = (json_object["metadata"]["redBoxCallGuid"])
        with open(r'C:/Users/folder/Documents/' + str(guid) + ".json", "w" ) as file:
            file.write(m)
            file.flush()
    #This bit does NOT WORK
        f = request.form.get("media_audio_wav")
        #print(f)
        with open(r'C:/Users/folder/Documents/' + str(guid) + ".wav", "wb" ) as file:
            file.write(f)
            file.flush()

Error Message: Error Message

Files Created: Files Created

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Andrew
  • 9
  • 2
  • 1
    Please post error messages as text. – SuperStormer Mar 08 '22 at 01:37
  • Can you post the relevant HTML? – SuperStormer Mar 08 '22 at 01:40
  • have you tried casting the resulting string into binary? – Kristian Mar 08 '22 at 03:34
  • always put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Mar 08 '22 at 04:50
  • `get` may gives some string and it may need to `encode()` . But in Flask files from form usually are available as `request.files`. But if some API sends file then it sends as string `base64` which has to be encoded from `base64` to bytes (using module `base64`). – furas Mar 08 '22 at 04:54

0 Answers0