1
HttpClient httpclient1 = new DefaultHttpClient();

HttpParams p=new BasicHttpParams();

p.setParameter("vname",name);
p.setParameter("address", addr);
p.setParameter("age", age);
p.setParameter("contact", cnct);
p.setParameter("gender", gen);
p.setParameter("whomto", wtm);
p.setParameter("myFile", f);

HttpPost res1=new HttpPost(result);
res1.setHeader("Content-Type", "text/plain");
res1.setHeader("Content-Type","image/jpeg");

HttpResponse response1 = httpclient1.execute(res1);
HttpEntity entity1 = response1.getEntity();
i1 = entity1.getContent();
BufferedReader reader1 = new BufferedReader(new InputStreamReader(i1,"iso-8859-1"),8);
StringBuilder sb1 = new StringBuilder();
String line1 = null;

if((line1 = reader1.readLine()) != null) {

    sb1.append(line1);
    back=sb1.toString();
}
else{
    Log.e("GET data","null");
}
i1.close();
Log.e("GET",""+back);  

//Server Code private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {

    res.setContentType("text/html");

    Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
    BlobKey blobKey = blobs.get("myFile");
    final BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(new BlobKey(blobKey.getKeyString()));
    System.out.println(blobInfo.getContentType());
    if(!blobInfo.getContentType().equalsIgnoreCase("image/jpeg")){
        blobstoreService.delete(blobInfo.getBlobKey());
        res.getWriter().println("Please Provide JPG image only");

    }       

I am sending one image file with some other data to server.I am not getting any error or exception But when I am printing the "back",in log it is showing "The request's content type is not accepted on this URL". "f" is my image file..What is the problem?

Sankar V
  • 4,794
  • 3
  • 38
  • 56
  • This might be an issue in the server code, which specifies what content types it accepts for that URL. Can you share that part of the server code? – Yusuf X Aug 09 '12 at 06:32
  • public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException { res.setContentType("text/html"); Map blobs = blobstoreService.getUploadedBlobs(req); BlobKey blobKey = blobs.get("myFile"); final BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(new BlobKey(blobKey.getKeyString())); System.out.println(blobInfo.getContentType()); if(!blobInfo.getContentType().equalsIgnoreCase("image/jpeg")){ blobstoreService.delete(blobInfo.getBlobKey()); res.getWriter().println("Please Provide JPG image only"); } – Rohan Deokar Aug 09 '12 at 07:20
  • In the previous code i am sending the image file through f. – Rohan Deokar Aug 09 '12 at 07:23

2 Answers2

0

Have a look at my answer to a similar question as yours: link It will save you the hassle of writing server side code and letting you android app send data eg. images to it.

Community
  • 1
  • 1
Luke Taylor
  • 9,481
  • 13
  • 41
  • 73
0

You are setting the Content-Type header to two different values, neither of which is "multipart/form-data" which I believe is what you need when sending an file.

Here is an answer that should help: https://stackoverflow.com/a/3003402/412558

Community
  • 1
  • 1
Ryan Bavetta
  • 865
  • 8
  • 21