In my android application, i am uploading images to the server(C#) via http post and its successfully uploaded to the server.
Hear is the code for image upload:
public static String uploadImagePost(String url, String imagePath) throws Exception { HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); HttpPost httpPost = new HttpPost(url); // add header httpPost.addHeader("FileName", "android"+System.currentTimeMillis()+".jpg"); httpPost.setHeader("User-Agent", "android_client"); httpPost.addHeader("accept", "application/json"); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); /* example for setting a HttpMultipartMode */ builder.setMode(HttpMultipartMode.RFC6532); /* example for adding an image part */ builder.addPart("image/jpeg", new FileBody(new File (imagePath))); httpPost.setEntity(builder.build()); HttpResponse response = httpClient.execute(httpPost, localContext); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } return result.toString(); } So my problem is the image witch i have uploaded is not readable. then i have check the source of the image using editor so i have noticed following text lines are included in the image source.
Header:
--5VkWFM_KqrrWu4l-DOUIyJabHz5tZ5_jp Content-Disposition: form-data; name="image/jpeg"; filename="tempimage.jpg" Content-Type: application/octet-stream Footer:
--5VkWFM_KqrrWu4l-DOUIyJabHz5tZ5_jp After removing of above header and footer and save the image so image is now readable.So the problem is header and footer. How can i fixed this issue?