0

I'm using android volley - http multipart request to post a mime file to my php server. Php 5.4.3 can catch the attachment file but php 5.3.3 didn't:

$_FILES['uploadedfile'] == empty array

(the request is good - good request length).

Can someone explains? Why php 5.3.3 didn't? Thanks, I'm new in PHP.

How to send a “multipart/form-data” POST in Android with Volley

My http request:

{MultipartFormEntity@830061806024} 
 multipart = {HttpBrowserCompatibleMultipart@830061809784} 
  parts = {ArrayList@830059119584}  size = 1
   0 = {FormBodyPart@830067533016} 
    body = {ByteArrayBody@830067487680} 
    header = {Header@830067537968} "[Content-Disposition: form-data; name="uploadedfile"; filename="test.mim", Content-Type: application/octet-stream, Content-Transfer-Encoding: binary]"
    name = {String@830059743272} "uploadedfile"
  boundary = {String@830061809752} "6ANZ75BgJPrWEv1L0jU9o-IKj5ftRzcpKiBqY7N"
  charset = {CharsetICU@830037109480} "java.nio.charset.CharsetICU[UTF-8]"
  subType = {String@830057480912} "form-data"
 contentType = {BasicHeader@830061692384} "Content-Type: multipart/form-data; boundary=6ANZ75BgJPrWEv1L0jU9o-IKj5ftRzcpKiBqY7N; charset=UTF-8"
  name = {String@830037147880} "Content-Type"
  value = {String@830061806056} "multipart/form-data; boundary=6ANZ75BgJPrWEv1L0jU9o-IKj5ftRzcpKiBqY7N; charset=UTF-8"
 contentLength = 4299
Community
  • 1
  • 1
Anh-Tuan Mai
  • 1,129
  • 19
  • 36
  • In the link in your question, try reading @Kevin comment at my answer to see if it can be the same issue for your PHP server or not. – BNK Sep 25 '15 at 15:15
  • I'm using "org.apache.httpcomponents:httpclient-android:4.3.5" and in class "org.apache.http.entity.mime.FormBodyPart" the space is good. Anyway, thanks for your help. – Anh-Tuan Mai Sep 25 '15 at 15:26
  • 1
    My answer has 2 option: with or without Apache Http :) – BNK Sep 25 '15 at 15:30
  • 1
    Your solution without apache http worked! Thank you very much. I'm looking deeper for the reason (possibly your getBody() function makes it works) – Anh-Tuan Mai Sep 28 '15 at 13:26
  • You are welcome! Goodluck! – BNK Sep 28 '15 at 14:17

1 Answers1

1

This code broke php function:

    try {
        entityBuilder.setCharset(CharsetUtils.get("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

>> Content-Type =
    multipart/form-data; boundary=1ft_IEmfaejQeazBUZDaPUqA-bkzkalk0; charset=UTF-8

In fact, this code above made php server doesn't get the uploaded file since it having charset type after boundary part. The Content-Type below make my code works:

    multipart/form-data; boundary=1ft_IEmfaejQeazBUZDaPUqA-bkzkalk0

I guest in some version, php server dont recognize uploaded file in first case. Thanks BNK very much for your suggestion.

Anh-Tuan Mai
  • 1,129
  • 19
  • 36