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

Error: open failed: ENOENT (No such file or directory) #99

Closed
immujahidkhan opened this issue Mar 24, 2021 · 20 comments · Fixed by #107 or #112
Closed

Error: open failed: ENOENT (No such file or directory) #99

immujahidkhan opened this issue Mar 24, 2021 · 20 comments · Fixed by #107 or #112
Assignees

Comments

@immujahidkhan
Copy link

immujahidkhan commented Mar 24, 2021

  • Lib Version : 2.2.2

After cropping image i found this issue that says Error: open failed: ENOENT (No such file or directory)

To Reproduce
Steps to reproduce the behavior:

  1. After setup library
  2. Start CropImageActivity
  3. Then crop image then it will show

Expected behavior
In previous library of https://github.com/edmodo/cropper its working fine but in your library its showing above error

Screenshots
image

Smartphone :

  • Device: Infinix note 7
  • OS: 10
@Canato
Copy link
Member

Canato commented Mar 24, 2021

Hey @immujahidkhan could you please give us more information about the bug?

Please fill the template, otherwise I cannot understand where this happen, if was from the library, which way are you using the library etc.

Bug Template

- Lib Version [e.g. 1.1.0]
 
**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Smartphone (please complete the following information):**
 - Device: [e.g. Pixel 3XL]
 - OS: [e.g. iOS8.1]

**Additional context**
Add any other context about the problem here.

@Canato
Copy link
Member

Canato commented Mar 24, 2021

@immujahidkhan I could not reproduce on the sample app in this library. You could try?

This do not look like a library issue, but maybe you code is trying to access the file where now is content since the last Android changes for permissions in OS 10 and OS 11.

You can read more here

Let me know if this is the same case or a new one

@immujahidkhan
Copy link
Author

i want to setImageURI like binding.userPhoto.setImageURI(result.getUri()); but can't

@Canato
Copy link
Member

Canato commented Mar 24, 2021

i want to setImageURI like binding.userPhoto.setImageURI(result.getUri()); but can't

Can you post the code where the exception is being throwing? (the one on the screenshot)

And please show the code where you are calling the library and retrieving the result. So I can understand how you are using it

@tyrellMitnick
Copy link

i want to setImageURI like binding.userPhoto.setImageURI(result.getUri()); but can't

you can use
binding.userPhoto.setImageBitmap(BitmapFactory.decodeFile(result.getUri().getPath()));

@hassanargon
Copy link

hassanargon commented Apr 7, 2021

I am facing the same issue when I am uploading images to the server in multipart/form-data.
Error message: ENOENT(No such file or directory)
Libray version: 2.3.1

@Canato
Copy link
Member

Canato commented Apr 7, 2021

I am facing the same issue when I am uploading images to the server in multipart/form-data.
Error message: ENOENT(No such file or directory)
Libray version: 2.3.1

@hassanargon

  • Can you please provide code sample?
  • Can you reproduce on the sample app in this repository?
  • Did you read the uri discussion ?

@hassanargon
Copy link

@Canato

  1. I am getting the image from the device gallery. and then pass the URI of this image into the library like this:
    CropImage.INSTANCE.activity(imageUri).start(requireContext(), this)
  2. And after crop I am getting the result into onActivityResult and save the URI that I got from this :
    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { CropImage.ActivityResult result = CropImage.INSTANCE.getActivityResult(data); Uri resultUri; if (result != null) { resultUri = result.getUri(); final InputStream imageStream; try { imageStream = requireActivity().getContentResolver().openInputStream(resultUri); final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream); delete_icon.setVisibility(View.VISIBLE); edit_icon.setVisibility(View.VISIBLE); Picasso.get().load(resultUri).resize(720, 1280).onlyScaleDown().into(imageView); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
  3. I am saving the resultUri into the list but when I convert this URI into multipart/form-data and send the response t server then it shows me this error ENOENT(No such file or directory)

@spungkyb
Copy link

spungkyb commented Apr 8, 2021

I also getting error Error: open failed: ENOENT (No such file or directory), i think it's because save in shared storage

@Canato
Copy link
Member

Canato commented Apr 8, 2021

Changes to be done here: #107

@Canato Canato self-assigned this Apr 8, 2021
@Canato Canato mentioned this issue Apr 13, 2021
4 tasks
@Canato
Copy link
Member

Canato commented Apr 13, 2021

Please try the latest 3.0.0 release and let me know

@fajar2304
Copy link

Hi @Canato i already implement 3.0.0 but still show

java.lang.RuntimeException: Failed to load sampled bitmap: content://com.android.cropper.fileprovider/my_images/Pictures/pickImageResult.jpeg
System.err: open failed: ENOENT (No such file or directory)
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
         Uri uri = CropImage.getPickImageResultUriContent(activity, data);
         CropImage.ActivityBuilder crop = CropImage.activity(uri).start(activity);
    }

problem on Samsung A71 and Samsung M31 Android 11

already add permission scope storage mean

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

i don't know how to fixed this, please help me
thank you

@Canato
Copy link
Member

Canato commented Apr 14, 2021

@fajar2304 if you want the FilePath, please use getPickImageResultUriFilePath and not getPickImageResultUriContent

Let me know if works please

@fajar2304
Copy link

@Canato thank you for respond, sorry still not working

java.lang.RuntimeException: Failed to load sampled bitmap: /data/user/0/com.android.crop/cache/temp_file.jpg
System.err: No content provider: /data/user/0/com.android.crop/cache/temp_file.jpg

@Canato
Copy link
Member

Canato commented Apr 14, 2021

@fajar2304 can you do a test in something manual please? If works I can make a hotfix

add file:// to the string. Meaning: /data/user/0/com.android.crop/cache/temp_file.jpg will became file:///data/user/0/com.android.crop/cache/temp_file.jpg

@fajar2304
Copy link

@Canato still error like this

java.lang.RuntimeException: Failed to load sampled bitmap: file:///data/user/0/com.android.crop/cache/temp_file.jpg
System.err: File is not a picture

but before show this first log show like this

java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
System.err:     at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:344)
System.err:     at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:231)
System.err:     at androidx.core.content.FileProvider.openFile(SourceFile:566)
System.err:     at android.content.ContentProvider.openAssetFile(ContentProvider.java:2032)
System.err:     at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:2214)
System.err:     at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:2281)
System.err:     at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:558)
System.err:     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2010)
System.err:     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1825)
System.err:     at android.content.ContentResolver.openInputStream(ContentResolver.java:1502)
System.err:     at e.d.a.j.a.c(SourceFile:41)
System.err:     at e.d.a.j.a.d(SourceFile:26)
System.err:     at com.canhub.cropper.CropImage.i(SourceFile:406)
System.err:     at e.s.a.a.e.h.b(SourceFile:77)
System.err:     at com.android.crop.Camera.onActivityResult(SourceFile:286)
System.err:     at android.app.Activity.dispatchActivityResult(Activity.java:8508)
System.err:     at android.app.ActivityThread.deliverResults(ActivityThread.java:5150)
System.err:     at android.app.ActivityThread.handleSendResult(ActivityThread.java:5198)
System.err:     at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2135)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
System.err:     at android.os.Looper.loop(Looper.java:236)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:8060)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

@Canato
Copy link
Member

Canato commented Apr 15, 2021

@fajar2304 I will need to take a look with more time.

If you have the chance please reproduce this bug on the sample code. Hard for me to debug if I can't reproduce locally =/
And open a new issue, so we can make visible for everyone =D

@pintu236
Copy link

pintu236 commented Aug 12, 2021

I was able to solve this issue
by first converting result uri into bitmap then save it to file.

` ActivityResultLauncher<CropImageContractOptions> cropImageContractOptionsActivityResultLauncher = registerForActivityResult(new CropImageContract(), result -> {
            if (result.isSuccessful()) {
                uriContent = result.getUriContent();
                Bitmap bitmap = Helper.getBitmap(this, uriContent);
                File selectedImgFile = new File(
                        getExternalFilesDir(Environment.DIRECTORY_PICTURES),
                        Timing.getCurrentTimeEpoch() + "_selectedImg.jpg");
                Helper.convertBitmapToFile(selectedImgFile, bitmap);

                profileViewmodel.uploadimage(selectedImgFile.getPath());
            } else {
                showMessage(R.string.failed_to_upload);
            }
        });`
    public static Bitmap getBitmap(Context context, Uri imageURI) {
        try {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
                return ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.getContentResolver(), imageURI));
            } else {
                InputStream
                        inputStream = context.getContentResolver().openInputStream(imageURI);
                return BitmapFactory.decodeStream(inputStream);

            }
        } catch (Exception e) {
            return null;
        }

    }

    public static void convertBitmapToFile(File dFile, Bitmap bitmap) {
        try {
            //create a file to write bitmap data
            boolean newFile = dFile.createNewFile();
            //Convert bitmap to byte array
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
            byte[] bytes = byteArrayOutputStream.toByteArray();
            //write the bytes in file
            FileOutputStream fileOutputStream = new FileOutputStream(dFile);
            fileOutputStream.write(bytes);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (Exception e) {
            Log.d(Helper.class.getSimpleName(), e.getLocalizedMessage());
        }
    }

@Ehtisham95
Copy link

I was able to solve this issue by first converting result uri into bitmap then save it to file.

` ActivityResultLauncher<CropImageContractOptions> cropImageContractOptionsActivityResultLauncher = registerForActivityResult(new CropImageContract(), result -> {
            if (result.isSuccessful()) {
                uriContent = result.getUriContent();
                Bitmap bitmap = Helper.getBitmap(this, uriContent);
                File selectedImgFile = new File(
                        getExternalFilesDir(Environment.DIRECTORY_PICTURES),
                        Timing.getCurrentTimeEpoch() + "_selectedImg.jpg");
                Helper.convertBitmapToFile(selectedImgFile, bitmap);

                profileViewmodel.uploadimage(selectedImgFile.getPath());
            } else {
                showMessage(R.string.failed_to_upload);
            }
        });`
    public static Bitmap getBitmap(Context context, Uri imageURI) {
        try {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
                return ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.getContentResolver(), imageURI));
            } else {
                InputStream
                        inputStream = context.getContentResolver().openInputStream(imageURI);
                return BitmapFactory.decodeStream(inputStream);

            }
        } catch (Exception e) {
            return null;
        }

    }

    public static void convertBitmapToFile(File dFile, Bitmap bitmap) {
        try {
            //create a file to write bitmap data
            boolean newFile = dFile.createNewFile();
            //Convert bitmap to byte array
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteArrayOutputStream);
            byte[] bytes = byteArrayOutputStream.toByteArray();
            //write the bytes in file
            FileOutputStream fileOutputStream = new FileOutputStream(dFile);
            fileOutputStream.write(bytes);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (Exception e) {
            Log.d(Helper.class.getSimpleName(), e.getLocalizedMessage());
        }
    }

Seems like this is the workaround so far. Though I will rather create a temporary file. I am getting this issue on Android 12 on Pixel 5.

@Canato
Copy link
Member

Canato commented Oct 26, 2021

please open a new issue with the bug template and the reproduce behaviour on the sample code so we can take a look =D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants