从相机捕获图像后,我试图上传图像。如下面的代码所示,但是它正在发送缩略图。
我还有另一个意图,那就是从设备库中上传图像,但效果很好。如何在不使用图库的情况下上传完整尺寸的图像?
更新1-如上文所述,我可以将捕获的图像上传到服务器,但是我没有得到全尺寸图像,该图像的尺寸大大小于预期。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_CAMERA_PERMISSION_CODE);
} else {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri();
intent.putExtra( MediaStore.EXTRA_OUTPUT, fileUri );
startActivityForResult(intent, REQUEST_CAMERA);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CAMERA:
bitmapImage = (Bitmap) Objects.requireNonNull(data.getExtras()).get("data");
image1.setImageBitmap(bitmapImage);
imagesPath = saveImageToDisk(bitmapImage);
File file = new File(imagesPath);
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"),file);
MultipartBody.Part body = MultipartBody.Part.createFormData("files", file.getName(), requestFile);
api = RetrofitClient.getClient(lGatewayUrl).create(APIService.class);
api.UploadImage("files",body).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.code() == 200){
Toast.makeText(getActivity(), "Image successfully uploaded ", Toast.LENGTH_SHORT).show();
}
}