Trying to figure what\'s wrong with my codings. I followed a blog post from here.
I managed to get the codes to actually upload the file to a PHP web service. However, f
I just had the same issue when updating HttpClient from version 4.1 to version 4.4. Neither removing HttpMultipartMode.BROWSER_COMPATIBLE
nor replacing with other alternative options did help.
A solution that requires the minimum change for me is to explicitly specify the filename
when constructing a FileBody
, i.e. replacing
new FileBody(file, mimeType)
with
new FileBody(file, filename, mimeType, charset)
As for version HttpClient 4.4, the reason might be that new FileBody(file, mimeType)
assigns null
to the filename
field rather than uses file.getName()
. Then, when executing formatMultipartHeader
in HttpMultipart
, the filename
of the part that is going to be formatted is checked if not null in BROWSER_COMPATIBLE
mode. If null, then the whole body is ignored.