Search code examples
flutterdartmultipartform-data

can not specify the content type of MultiPartFile in Flutter


I'm trying to send an image to a server via multiPartRequest in flutter and when I add the image into the request files, once I want to specify the content type which is of MediaType, a compile-time error appear telling me that MediaType class is not defined.

How can I fix this problem?

http.MultipartRequest multipartRequest = new http.MultipartRequest('POST',url);
http.MultipartFile file = new http.MultipartFile.fromBytes('file', await 
image.readAsBytes(),contentType: MediaType('image','jpg));  // MediaType class is not defined
multipartRequest.files.add(file);

Solution

  • I figured out the answer and it is that I must import http parser package