-1

Below is requesting parameters what I tried with postman and is working fine

Postman request Parameter

However, I am not able to do the same pragmatically from Android.

Below is what I tried

File urls= new File(fn)

Part[] parts = new Part[1];
for (int i = 0; i < parts.length; i++) {
try {
      parts[i] = new FilePart("image", urls);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
}

MultipartEntity reqEntity = new MultipartEntity(parts,httpPost.getParams());
httpPost.setEntity(reqEntity);

would appreciate the solution

Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45
Atul Dhanuka
  • 1,453
  • 5
  • 20
  • 56
  • There isn't really enough code there to see what you're trying and no description of why it doesn't work. – hardillb Jun 01 '17 at 11:50

1 Answers1

0

You can try using Android Upload Service library. I have used it several times in my organization's production apps without fail.

Steps to follow (as shown on Github Wiki) -

1) Setup

2) Multi-part Upload Example

Below is the recipe for quick review -

public void uploadMultipart(final Context context) {
    try {
        String uploadId =
          new MultipartUploadRequest(context, "http://upload.server.com/path")
            // starting from 3.1+, you can also use content:// URI string instead of absolute file
            .addFileToUpload("/absolute/path/to/your/file", "your-param-name")
            .setNotificationConfig(new UploadNotificationConfig())
            .setMaxRetries(2)
            .startUpload();
    } catch (Exception exc) {
        Log.e("AndroidUploadService", exc.getMessage(), exc);
    }
}
Kunal Chawla
  • 1,236
  • 2
  • 11
  • 24