0

I am sending a multipart request,and my file is attached like this

    entity.addPart(entry.getValue().getName(), new FileBody(entry.getValue(), entry.getValue().getName(), "image/jpeg", "ISO-8859-1"));

entity is an MultipartEntityBuilder object.

I want to set content disposition also .How can I set content disposition with the file?Please help

Raji A C
  • 2,261
  • 4
  • 26
  • 31

1 Answers1

0

Try This:-

InputStream inputStream = new FileInputStream(new File(String.valueOf(params[0])));

//*** CONVERT INPUTSTREAM TO BYTE ARRAY
byte[] data = this.convertToByteArray(inputStream);

            HttpClient httpClient = new DefaultHttpClient();


HttpPost httpPost = new HttpPost(UPLOAD_SERVER_URI);

String boundary = "----WebKitFormBoundarypJjqFVXFVatNaatW";

httpPost.setHeader("Accept", "*/*");
httpPost.setHeader("Content-type", "multipart/form-data; boundary="+boundary);

//File Data
InputStreamBody inputStreamBody = new InputStreamBody(new ByteArrayInputStream(data), "image/jpeg");

    CustomMultiPartEntity multipartEntity = new CustomMultiPartEntity();

            // SET UPLOAD LISTENER
            multipartEntity.setUploadProgressListener(this);

            //*** ADD THE FILE
            multipartEntity.addPart("imagecode", inputStreamBody);

            /** Add String Data */
            entity.addPart("companycode", new StringBody(companycode));

            httpPost.setEntity(multipartEntity);

            // EXECUTE HTTPPOST
            HttpResponse httpResponse = httpClient.execute(httpPost);

            // THE RESPONSE FROM SERVER
            String stringResponse = EntityUtils.toString(httpResponse.getEntity());

            // DISPLAY RESPONSE OF THE SERVER
            Log.d("data from server", stringResponse);
Chaudhary Amar
  • 836
  • 8
  • 20
  • My question is about setting Content-Disposition e.g.:-Content-Disposition: form-data; name="attach3"; filename="file.jpg" – Raji A C Oct 26 '15 at 13:05
  • I am using Request class in volley not basic HttpClient.If we are using Volley there is a class called FormBodyPart which will set content type and content disposition.My mistake was I didn't supply full filename,just specified filename without extension. – Raji A C Oct 27 '15 at 05:14
  • @RajiAC Means you find the solution. – Chaudhary Amar Oct 27 '15 at 05:32