title: How to get type of uploaded file into MediaType
body: <p>I'm using http package on my dart client side for uploading my images to server. </p>
  
  <pre><code> Future&lt;void&gt; createProfile(Profile profile) async {
      try {
        var request =
            new http.MultipartRequest("POST", Uri.parse(APIPath.createProfile()));
        request.fields.addAll(profile.toMap());
        request.files.add(await http.MultipartFile.fromPath(
            'image', profile.image.path,
            contentType: MediaType('image', 'png'))); //&lt;- specified png image type
        request.headers['authorization'] = "Bearer $_token";
        final response = await request.send();
        if (response.statusCode == 200) print('Uploaded!');
  
        notifyListeners();
        return response;
      } catch (error) {
        throw error;
      }
    }
  </code></pre>
  
  <p>and I'm using Multer in my server side node.js to allow certain type of images</p>
  
  <pre><code>const fileFilter = (req, file, cb) =&gt; {
     console.log(file.mimetype); //&lt;-- prints image/png for jpg files
     if (file.mimetype === 'image/png' || file.mimetype === 'image/gif' || file.mimetype === 'image/jpg' || file.mimetype === 'image/jpeg') {
        cb(null, true);
     } else {
        const error = new Error('Only images are allowed')
        error.statusCode = 406;
        cb(error);
     }
  }
  </code></pre>
  
  <p>I have noticed that when image of type <code>jpg</code> is uploaded from my client side to server then in server is recognised as <code>png</code> specified in <code>contentType: MediaType('image', 'png')</code> but saved as <code>jpg</code>. I want to only allowed types specified in my server so how can I get current uploaded image type into my <code>MediaType</code> without hardcoding it <code>MediaType('image', 'png')</code>?</p>