Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-8 encoding with FileBody in MultipartEntity

I want to set UTF-8 encoding while files sending in FileBody as I do it in a StringBuilder. I do it like this:

restClient.AddEntity("body", new StringBody(body, Charset.forName("UTF-8")));

and it works properly if I send different from UTF-8 messages encoding. But if I do like this:

ContentBody fbody = new FileBody(( File )file, "application/octet-stream","UTF-8");
        restClient.AddEntity("files[]", fbody);

server get files names not in UTF-8. How can I fix it?

like image 949
Rikki Tikki Tavi Avatar asked Oct 29 '12 17:10

Rikki Tikki Tavi


2 Answers

I solve this issue, by this params:

entity.addPart("video_title", new StringBody(edtvideo_title.getText().toString(),Charset.forName(HTTP.UTF_8)));
like image 28
Iman Marashi Avatar answered Nov 09 '22 09:11

Iman Marashi


I solve this issue simply, by:

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,null,Charset.forName("UTF-8"));
like image 85
Rikki Tikki Tavi Avatar answered Nov 09 '22 07:11

Rikki Tikki Tavi