从昨天开始,我一直在努力尝试将使用移动相机从 iOS/Android 设备拍摄的图像上传到 azure blob 存储。
我可以上传文件,但由于某种原因它们已损坏,无法打开上传的图像。
打开上传的图片时请检查图片错误

我正在使用 flutter 包 http,采用不同的方法将图像文件上传到 azure blob 存储,但它以某种方式损坏,我尝试强制ContentType但image/jpeg没有帮助。
这是我正在使用 http API 的代码 -
takePicture() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
String fileName = basename(pickedFile.path);
uploadFile(fileName, image);
} else {
print('No image selected.');
}
});
}
Run Code Online (Sandbox Code Playgroud)
第一种方法 -->
http.Response response = await http.put(
uri,
headers: {
"Content-Type": 'image/jpeg',
"X-MS-BLOB-TYPE": "BlockBlob",
},
body: image.path,
);
print(response.statusCode);
Run Code Online (Sandbox Code Playgroud)
使用第二种方法 -->
final …Run Code Online (Sandbox Code Playgroud)