I am trying to upload an image from a flutter android app to server (running on flask-python). I have used swagger 2.0 to generate both flask server and dart client api code. I am getting error 'Key error: file' on my server side whenever I try to call the image upload api.
Setup:
Client: flutter client on android
Server: Flask Python
Both are setup using Swagger 2.0
I have tried calling the api from SOAP UI and it works perfectly and my image gets uploaded to the server. However, when I try to call the same image upload api from android app via flutter api, it gives me error on my server.
SOAP UI call parameters:
Method: POST
Endpoint: http://localhost:5000
Resource: /images
Post QueryString = true
Parameters:
inFile file:[filename that I have uploaded in the attachment section]
Swagger configuration:
post:
description: Creates a new Image
operationId: createNewImage
consumes:
- multipart/form-data
parameters:
- in: formData
name: inFile
type: file
required: true
description: Image file to upload.
- in: formData
name: imageDescription
type: string
required: false
description: Description of image file
responses:
'200':
description: 200 response
schema:
$ref: '#/definitions/ImageRespModel'
Flutter Api calling code (Not working):
var api = new ServerApi.ImagesApi();
File _image = <image object clicked from camera>
String _filename = path.basename(_image.path);
MultipartFile _imageFile = MultipartFile.fromBytes(
'inFile', _image.readAsBytesSync(),
filename: _filename);
api.createNewImage(_imageFile);
Expected Results: The android api call should be able to upload the code in the same way as I am able to do it from SOAP UI. I think I am missing something in the android api call setup.
Error on the python server:
type_func = TYPE_MAP[_type] # convert value to right type
KeyError: 'file'