Friends,
I have to Upload an Image and related Data to ASP.net API(Server).
API , I tested with Postman and it works fine. But I am not able to Upload that from Flutter.
It Shows Loading and not getting any response.
So please help me to fix this issue.
I have uploaded an Image of my code here and add the same below.
CODE
Future> imageUploader(File fl) async
{
print("Inside imageUploader() File = $fl");
setState(()
{
pr.show();
});
final mimeTypeData = lookupMimeType(fl.path, headerBytes: [0xFF, 0xD8]).split('/');
final imageUploadRequest = http.MultipartRequest('POST', apiUrl);
final fileNew = await http.MultipartFile.fromPath('half_body_image', fl.path,contentType: MediaType(mimeTypeData[0], mimeTypeData[1]));
imageUploadRequest.files.add(fl);
imageUploadRequest.fields['name'] = imgFileName;
imageUploadRequest.fields['imgCatag1'] = imgCategory1;
try
{
final streamedResponse = await imageUploadRequest.send();
final response = await http.Response.fromStream(streamedResponse);
if (response.statusCode != 200)
{
return null;
}
final Map<String, dynamic> responseData = json.decode(response.body);
return responseData;
}
catch (e)
{
print(e);
return null;
}
}
Top comments (0)