How to upload images and file to a server in Flutter?

后端 未结 11 1049
攒了一身酷
攒了一身酷 2020-11-29 22:21

I use a web service for image processing , it works well in Postman:

Now I want to make http request in flutter with Dart:

import \'pa         


        
11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 22:51

    I use Dio library with put method:

        var formData = FormData.fromMap({
          'simpleParam': 'example',
          'file': await MultipartFile.fromFile(filePath, filename: 'file.jpg')
        });
    
        var dio = Dio();
        dio.options.headers[HttpHeaders.authorizationHeader] = myToken;
    
        var response = new Response(); //Response from Dio
        response = await dio.put(myUrl + "/myApi", data: formData);
    

    The result is in response.data

提交回复
热议问题