无法解析从dio flutter发送的服务器中的formdatafields

时间:2019-06-13 12:10:24

标签: flask flutter

我正在使用https://pub.dev/packages/dio向服务器发送请求。她是我的代码:

Future<bool> initialConfig(String name, String status, File image) async {
    try {
      this._dio = Dio(options);
      final id = await UserKeyManagement().retriveKey();
      FormData formData = FormData.from(<String, dynamic>{
        "profile_pic": UploadFileInfo(image, image.path, contentType: ContentType.parse(lookupMimeType(image.path))),
        'id': id,
        'display_name': name,
        'status': status,
      });
      final response = await _dio.post('/initial_setup', data: formData);
      return response.data['success'];
    }catch(e) {
      return false;
    }
 }

这是我针对特定请求的烧瓶服务器代码:

from flask_restful import Resource, reqparse
import werkzeug
from firebase_admin import storage
from uuid import uuid4
from database.shared_db import db
from database.model.display_info_model import DisplayInfoModel

class InitialSetup(Resource):
    def post(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('profile_pic', type=werkzeug.FileStorage, location='files')
            parser.add_argument('display_name', type=str, location='form')
            parser.add_argument('id', type=str, location='form')
            parser.add_argument('status', type=str, location='form')
            args = parser.parse_args()
            bucket = storage.bucket()
            image = args['profile_pic']
            img_name = 'profile_pic/' + str(uuid4())
            blob = bucket.blob(img_name)
            blob.upload_from_file(file_obj=image, content_type=image.content_type)
            temp = DisplayInfoModel.query.filter_by(user_id=args['id']).first()
            temp.display_name = args['display_name']
            temp.status = args['status']
            temp.profile_pic = img_name
            db.session.commit()
            return {
                'success': True
            }
        except:
            return {
                'success': False
            }

我能够用表格数据中的所有参数完美地执行邮递员的请求。但是,当我尝试抖动时,它显示内部服务器错误。有人可以帮忙吗?

0 个答案:

没有答案