flutter dio upload image type application/octet-stream to image/jpeg

发布者: 粮油菜大市场 发布时间: 2021.11.29 06:56:02
   MediaType? mediaType;
    if (_fileToUpload.path.endsWith('jpg') ||
        _fileToUpload.path.endsWith('jpeg')) {
      mediaType = MediaType("image", "jpeg");
    } else if (_fileToUpload.path.endsWith('png')) {
      mediaType = MediaType("image", "png");
    }
    if (_fileToUpload.path.isNotEmpty) {
      // Create a FormData
      String fileName = basename(_fileToUpload.path);

      print("File Name : $fileName");
      print("File Size : ${_fileToUpload.lengthSync()}");
      print("File Type : $mediaType");
      _formData = FormData.fromMap({
        "product_images": await MultipartFile.fromFile(_fileToUpload.path,
            filename: fileName, contentType: mediaType)
      });
    }
 
解决方案就是更改contentType参数
评论
登陆评论

没有评论