2

I am using Loopj's android-async-http This is my code:

File file = new File("sdcard/food.jpg");
params.put("image", file);

My problem is, php server received the images as application/octet-stream instead of image/jpg. I need it to be image/jpg as my server guy white-list uploaded files that have types of image/jpg, image/png, etc.

UPDATE 1

I've tried adding content type parameter to the application. However, php code still recognized it as application/octet-stream.

params.put("image", new FileInputStream(file), "image/jpg");

UPDATE 2

Since I need to move on with the project, what we do right now is propose server guy to implement mime sniffing by using exif. In php, we do it with exif_imagetype(). All is well, so far. I will keep this question open until we find the solution that is implementable in android.

ariefbayu
  • 21,849
  • 12
  • 71
  • 92
  • 1
    have you tried specifying file name instead of mime type? like `params.put("image", new FileInputStream(file), "food.jpg");` – mask8 Mar 27 '14 at 02:36
  • it still doesn't work – ariefbayu Mar 27 '14 at 02:49
  • 1
    sorry I think it should be `params.put("image", new FileInputStream(file), "food.jpg", "image/jpg");` https://github.com/loopj/android-async-http/blob/master/library/src/main/java/com/loopj/android/http/RequestParams.java – mask8 Mar 27 '14 at 02:57
  • or it can also be `params.put("image", new File("sdcard/food.jpg"), "image/jpg");` according to api doc – mask8 Mar 27 '14 at 03:00
  • I also already did that :( – ariefbayu Mar 27 '14 at 03:12

1 Answers1

2

I have faced the same problem, yet I couldn't change application/octet-stream but I instead handle it on server:

    $info = getimagesize($_FILES['pic']['tmp_name']);
    $type=$info['mime'];

here the type will be shown as image/jpg instead of application/octet-stream.

Ann
  • 79
  • 1
  • 8