DEV Community

shan oa
shan oa

Posted on

1

Image and Data Upload Issue in Flutter.

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;
}

}

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay