Android file upload - $_FILES returns empty

后端 未结 3 1438
清歌不尽
清歌不尽 2021-01-22 07:02

I\'m trying to upload a image from Android App to a server with a PHP Script. The HTTP Response returns STATUS OK: 200, but the $_FILES[\"upfile\"][\"name\"] returns empty. I`ve

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-22 07:32

    I've just encountered the same issue. POSTing a file succeeds with a 200 response, but _FILES is empty. I fixed the issue by specifying the Content-Length header. E.g.:

    conn.setRequestProperty("Content-Length", Integer.toString(fileInputStream.available()));
    

    Edit: So, when using this, the file appeared in _FILES but with an error code of 3. However, I also had a call to conn.setChunkedStreamingMode(1024);. Removing the Content-Length and the call to setChunkedStreamingMode worked for me, but I'm pretty sure that the empty _FILES is to do with the Content-Length field not being set correctly.

提交回复
热议问题