I’m working on a critical issue regarding image uploading in Azure blob storage using sas token api.
While testing the functionality via Postman, we’ve observed that the image upload process is successful, yielding a status code of 201. However, when attempting the same operation from within our application, although we receive a status code of 201, the image fails to load.
Future<void> uploadImageToAzure() async {
await getUploadTokenAPi();
final image = await _signaturePadKey.currentState!.toImage();
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
setState(() {
});
bytes = byteData?.buffer.asUint8List(byteData.offsetInBytes,byteData.lengthInBytes);
setState(() {});
var headers = {
'x-ms-blob-content-type': 'image/png',
'x-ms-blob-type': 'BlockBlob',
'Content-type': 'application/octet-stream',
'Accept-Encoding': 'gzip, deflate, br',
'Cache-Control': 'max-age=0',
};
Dio dio = Dio();
// log("${base64Encode(bytes!)}");
Response response = await dio.put(
uploadtokenResponce.data["token"],
data: base64Encode(bytes!),
options: Options(
headers: headers,
),
);
if (response.statusCode == 201) {
print("================");
log(json.encode(response.headers.map));
print("================");
log("Data : ${response.statusCode}");
} else {
print(response.statusMessage);
}
try {} catch (e) {
print('Error uploading image: $e');
}
}
_signaturePadKey = this key use for take signature image
Ziyad godil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.