Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit f638161

Browse files
Sam1301kunall17
authored andcommitted
Refactor multipart.body out of uploadFile().
1 parent 1299d44 commit f638161

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.os.Environment;
2929
import android.os.Handler;
3030
import android.provider.MediaStore;
31+
import android.support.annotation.NonNull;
3132
import android.support.design.widget.AppBarLayout;
3233
import android.support.design.widget.CoordinatorLayout;
3334
import android.support.design.widget.FloatingActionButton;
@@ -1085,6 +1086,19 @@ private void startFileUpload() {
10851086
uploadFile(file);
10861087
}
10871088

1089+
@NonNull
1090+
private MultipartBody.Part prepareFilePart(String partName, File file) {
1091+
// create RequestBody instance from file
1092+
RequestBody requestFile =
1093+
RequestBody.create(
1094+
MediaType.parse("multipart/form-data"),
1095+
file
1096+
);
1097+
1098+
// MultipartBody.Part is used to send also the actual file name
1099+
return MultipartBody.Part.createFormData(partName, file.getName(), requestFile);
1100+
}
1101+
10881102
/**
10891103
* Function to upload file asynchronously to the server using retrofit callback
10901104
* upload {@link com.zulip.android.service.ZulipServices#upload(MultipartBody.Part)}
@@ -1093,13 +1107,8 @@ private void startFileUpload() {
10931107
*/
10941108
private void uploadFile(final File file) {
10951109

1096-
// create RequestBody instance from file
1097-
RequestBody requestFile =
1098-
RequestBody.create(MediaType.parse("multipart/form-data"), file);
1099-
11001110
// MultipartBody.Part is used to send also the actual file name
1101-
MultipartBody.Part body =
1102-
MultipartBody.Part.createFormData("file", file.getName(), requestFile);
1111+
MultipartBody.Part body = prepareFilePart("file", file);
11031112

11041113
final String loadingMsg = getResources().getString(R.string.uploading_message);
11051114

0 commit comments

Comments
 (0)