Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filename encoding for file upload #33

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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