upload method

Future<Response> upload()

Implementation

Future<Response> upload() async {
  var dio = Dio();
  var fileBytes = await file.readAsBytes();
  print("upload => 开始上传: ${file.path}");
  var response = await dio.post(
    'https://api.tinify.com/shrink',
    data: Stream.fromIterable(fileBytes.map((e) => [e])),
    options: Options(
      headers: {
        HttpHeaders.authorizationHeader:
            'Basic ${base64Encode(utf8.encode('api:${AKTinyImageManager.instance.tinyImageApiKey}'))}',//x2zpZtVlK4MJjDm03P6b1h1DhGzGR4c4
        HttpHeaders.contentTypeHeader: 'application/x-www-form-urlencoded',
      },
    ),
  );
  //{"input":{"size":1103,"type":"image/png"},"output":{"size":503,"type":"image/png","width":48,"height":48,"ratio":0.456,"url":"https://api.tinify.com/output/tad8gw16xa4ragj9vkfd7g0wtfd0cy1z"}}
  print("upload => 完成上传: ${response.statusCode} data: ${response.data}");
  return response;
}