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:[email protected]: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

1 Answer 1

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;
    }


}
Sign up to request clarification or add additional context in comments.

5 Comments

Arjun i need to send "file" also which is of String[] type. Check my Service Requirements.
I am new in Android can this helpful to add with MultipartEntity ---> for (String mArray: mSelectedCategoryArray) { entity .addPart("ArrayID[]", new StringBody(mArray)); }
see the answer on this quetion: -stackoverflow.com/questions/16293388/…
Thanks @Er Arjun let me check that.
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.