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

Commit 716a7cf

Browse files
Sam1301kunall17
authored andcommitted
Use media type of file being uploaded in RequestBody.
1 parent 1752e34 commit 716a7cf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ public void onReceive(Context contenxt, Intent intent) {
209209
private Uri mFileUri;
210210
private ImageView cameraBtn;
211211
private String mCurrentPhotoPath;
212-
private Uri mPhotoURI;
213212
private Menu menu;
214213
private Calendar calendar;
215214
private EditText etSearchPeople;
@@ -1019,16 +1018,16 @@ private void dispatchTakePictureIntent() {
10191018

10201019
// Continue only if the File was successfully created
10211020
if (photoFile != null) {
1022-
mPhotoURI = FileProvider.getUriForFile(this,
1021+
mFileUri = FileProvider.getUriForFile(this,
10231022
"com.zulip.fileprovider",
10241023
photoFile);
1025-
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoURI);
1024+
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
10261025

10271026
// grant uri permissions for lower api levels
10281027
List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);
10291028
for (ResolveInfo resolveInfo : resInfoList) {
10301029
String packageName = resolveInfo.activityInfo.packageName;
1031-
this.grantUriPermission(packageName, mPhotoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
1030+
this.grantUriPermission(packageName, mFileUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
10321031
}
10331032

10341033
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
@@ -1097,7 +1096,7 @@ private void uploadFile(final File file) {
10971096

10981097
// create RequestBody instance from file
10991098
RequestBody requestFile =
1100-
RequestBody.create(MediaType.parse("multipart/form-data"), file);
1099+
RequestBody.create(MediaType.parse(getContentResolver().getType(mFileUri)), file);
11011100

11021101
// MultipartBody.Part is used to send also the actual file name
11031102
MultipartBody.Part body =

0 commit comments

Comments
 (0)