1

I am using Volley Android Multipart VolleyMultipartRequest request class to upload various types of mime types. i.e, Image,Video,Audio,Document,PDF. Current i am using this method for uploading Image which is working fine.

        @Override
        protected Map<String, DataPart> getByteData() {
            Map<String, DataPart> params = new HashMap<>();
            params.put("Key", new DataPart("Filename", byte[], "image/jpeg"));
            return params;
        }

It is working absolutely fine but for image , what if i want to use this request for all mime types what should i put the last parameter for Video and PDF. For example for image "image/jpeg" being sent what will be for audio , video and pdf or doc, Any help will be much appropriated.

Ali Akram
  • 4,803
  • 3
  • 29
  • 38
  • Possible duplicate of [this](https://stackoverflow.com/questions/8589645/how-to-determine-mime-type-of-file-in-android) – Sandeep Singh Feb 18 '18 at 07:27
  • try this https://stackoverflow.com/questions/16797468/how-to-send-a-multipart-form-data-post-in-android-with-volley/ – Santanu Sur Feb 18 '18 at 07:29
  • @Sandeep Randhawa I am more interested in a solution to my problem than to see you profile. – Ali Akram Feb 18 '18 at 07:38
  • @AliAkram I didn't get you. But your basic problem was to get the mime-type for your file and I gave you solution already present in [here](https://stackoverflow.com/questions/8589645/how-to-determine-mime-type-of-file-in-android) – Sandeep Singh Feb 18 '18 at 07:45

1 Answers1

0

You can use below function to find out mimetype of file from the file path,Just pass the file path to this function and it will return te mime type of your file

public static String getMimeTypefromfilepath(String path) {
    String mimetype = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(path);
    if (extension != null) {
        mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    }
    return mimetype;
}
Shashwat Gupta
  • 876
  • 9
  • 22