1

I want to send String[] with file path in Multipart-Entity I got that link (My code is too big to post so i post reference link) in which @rohit mandiwal code works for for single image without string[], but now i have send multiple images with string[]

My Server side code for that service is something like that

@RequestMapping(value = "/Images", method = RequestMethod.POST)
@ResponseBody
@ResponseStatus(value = HttpStatus.OK)
public ImageFilePath uploadFileImage(
        @RequestParam("file") MultipartFile[] multipartFiles,@RequestParam("side") String[] sides)
        throws Exception {
    return AppointmentService.uploadFileImage(multipartFiles, sides);
}

But i am unable to send String[] side to that service by changing above code. Requirement for my service is something like

"Token:ulhas...@gmail.com:people:1460612590421:3f8eeae2f6d2a53c18117bca8952d018" -H "Content-Type:multipart/form-data" "myURL/appointment/myImages" -X POST -F file=@/home/ulhas/Desktop/desktopPdata/img_195753.jpg -F side=left -F file=@/home/ulhas/Desktop/desktopPdata/img_195753.jpg -F side=left
Community
  • 1
  • 1
ULHAS PATIL
  • 862
  • 8
  • 19

1 Answers1

0

Try this code..

private class webAsync extends AsyncTask<String, Integer, String> {

    private ProgressDialog pb = null;
    private HttpResponse httpResponse;
    private HttpPost postRequest;
    private HttpClient httpClient;
    private HttpEntity httpEntity;
    String Str_imagepath="path file";

    @Override
    protected String doInBackground(String... params) {



        String APP_SERVICE_DOMAIN = null;
        String mIncomingUrl = null;

            APP_SERVICE_DOMAIN = "URL webservice";

        mIncomingUrl = APP_SERVICE_DOMAIN;// add the field if any




        System.out.println("@Incoming Request URL ==" + mIncomingUrl);
        try {

            HttpPost httppost = new HttpPost(mIncomingUrl);

            MultipartEntity entity = new MultipartEntity();
            File myFile = new File(Str_imagepath);
            Log.e("TAG_FILE", "Exists1 " + myFile.exists());

            FileBody fileBody = new FileBody(myFile);
            if(myFile.exists()) {
                entity.addPart("image", fileBody);

     // webservice parameter for file
            }
      for (String mArray: mSelectedCategoryArray)
      {
     entity .addPart("ArrayID[]", new StringBody(mArray));
      } 

            httppost.setEntity(entity);
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse httpresponse = httpclient.execute(httppost);
            if (httpresponse.getEntity() != null) {
                String fileResponse = EntityUtils.toString(httpresponse
                        .getEntity());
                System.out.println("@@............." + fileResponse);



                return fileResponse;
            }
        } catch (Exception e) {


        }

        return null;
    }


}
Arjun saini
  • 4,223
  • 3
  • 23
  • 51
  • Arjun i need to send "file" also which is of String[] type. Check my Service Requirements. – ULHAS PATIL Apr 29 '16 at 06:55
  • I am new in Android can this helpful to add with MultipartEntity ---> for (String mArray: mSelectedCategoryArray) { entity .addPart("ArrayID[]", new StringBody(mArray)); } – Arjun saini Apr 29 '16 at 07:08
  • see the answer on this quetion: -http://stackoverflow.com/questions/16293388/how-to-send-the-string-array-of-values-in-one-key-word-using-post-method-to-the – Arjun saini Apr 29 '16 at 07:17
  • Thanks @Er Arjun let me check that. – ULHAS PATIL Apr 29 '16 at 07:25
  • No @Er Arjun it's not working for my service. I already checked that before but once again i check it as you mentioned but still not working – ULHAS PATIL Apr 29 '16 at 08:57