Flask-RESTful - Upload image

后端 未结 5 1934
再見小時候
再見小時候 2020-12-08 01:03

I was wondering on how do you upload files by creating an API service?

class UploadImage(Resource):
    def post(self, fname):
        file = request.files[\         


        
5条回答
  •  一生所求
    2020-12-08 01:41

    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

提交回复
热议问题