Flask-RESTful - Upload image
The following is enough to save the uploaded file:
from flask import Flask
from flask_restful import Resource, Api, reqparse
import werkzeug
class UploadImage(Resource):
def post(self):
parse = reqparse.RequestParser()
parse.add_argument('file', type=werkzeug.datastructures.FileStorage, location='files')
args = parse.parse_args()
image_file = args['file']
image_file.save("your_file_name.jpg")
class UploadWavAPI(Resource):
def post(self):
parse = reqparse.RequestParser()
parse.add_argument('audio', type=werkzeug.FileStorage, location='files')
args = parse.parse_args()
stream = args['audio'].stream
wav_file = wave.open(stream, 'rb')
signal = wav_file.readframes(-1)
signal = np.fromstring(signal, 'Int16')
fs = wav_file.getframerate()
wav_file.close()
You should process the stream, if it was a wav, the code above works. For an image, you should store on the database or upload to AWS S3 or Google Storage