Skip to content

Commit

Permalink
Merge pull request #33 from LiveTex/fix_upload
Browse files Browse the repository at this point in the history
Added filename encoding for file upload
  • Loading branch information
maxxx authored Dec 2, 2023
2 parents 5283da7 + e7a39fa commit 9be056a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdk/src/main/java/ru/livetex/sdk/network/ApiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Objects;

import com.google.gson.Gson;
Expand Down Expand Up @@ -57,9 +59,11 @@ public Single<FileUploadedResponse> uploadFile(File file) {
return;
}

String encodedFilename= URLEncoder.encode(file.getName(), "UTF-8");

RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("fileUpload", file.getName(),
.addFormDataPart("fileUpload", encodedFilename,
RequestBody.create(MediaType.parse("text/plain"), file))
.build();

Expand Down Expand Up @@ -178,12 +182,13 @@ private void uploadFile(
InputStreamProvider inputStreamProvider,
@Nullable MediaType mediaType,
SingleEmitter<FileUploadedResponse> emitter
) {
) throws UnsupportedEncodingException {
String encodedFilename= URLEncoder.encode(fileName, "UTF-8");
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(
"fileUpload",
fileName,
encodedFilename,
new RequestBody() {
@Override
public MediaType contentType() {
Expand Down

0 comments on commit 9be056a

Please sign in to comment.