-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
getting FileNotFoundException when passed content uri as destination #668
Comments
@ImRohithBajjuri did you find any solution of this ? I am getting the same issue. |
no and I'm still waiting for a response. recently there was an update to
the library and strangely it is giving the same exception even for a file
uri. For now I reverted back to old version
…On Thu, Aug 6, 2020 at 2:30 PM priyanka-poplify ***@***.***> wrote:
@ImRohithBajjuri <https://github.com/ImRohithBajjuri> did you find any
solution of this ? I am getting the same issue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#668 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIO6ZH2HY4KAGHH6XUTF743R7JWLZANCNFSM4OAJTUMA>
.
|
The same problem to me, working on it. f I get something, I'll let you know. |
Seems like the problem in destination URI. I've used the code from sample: val destinationUri = Uri.fromFile(File(getCacheDir(), "balbla.jpg")
UCrop.of(sourceUri, destinationUri)... |
|
passing content uri as destination gave the error, after converting it to file uri did work. But in the latest version passing the converted file uri is also giving the error. Is it because of the scoped storage thing? |
Probably, not sure. |
@ImRohithBajjuri Yes, it is. I'm with the same problem here. Steps to reproduce the error on Android 29+:
Intent createDocumentIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
createDocumentIntent.addCategory(Intent.CATEGORY_OPENABLE);
createDocumentIntent.setType("image/jpeg");
createDocumentIntent.putExtra(Intent.EXTRA_TITLE, createCroppedPictureNameFrom(cameraFile.getName()));
startActivityForResult(createDocumentIntent, EXTERNAL_IMAGE_FILE_REQUEST_CODE);
if(requestCode == EXTERNAL_IMAGE_FILE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
if (data != null) {
//Saving in the chosen external directory
Uri destinationUri = data.getData();
Uri sourceUri = Uri.fromFile(cameraFile);
UCrop.of(sourceUri, destinationUri)
.withMaxResultSize(1024, 1024)
.start(this);
}
} else if (resultCode == RESULT_CANCELED) {
//Explain to user that no file will be saved (maybe do this once and save state)
}
}
else if(requestCode == UCrop.REQUEST_CROP) {
if (resultCode == RESULT_OK) {
final Uri resultUri = UCrop.getOutput(data);
ImageUtils.loadImage(resultUri, mImageView, this);
} else if (resultCode == UCrop.RESULT_ERROR) {
final Throwable cropError = UCrop.getError(data);
Log.d(LOG_TAG, "Cropping error", cropError);
}
if (cameraFile != null) {
//Tmp file is no more required
cameraFile.delete();
}
}
|
Debugging uCrop code, I can see that the problem starts on the onPostExecute method of the BitmapLoadTask class: @Override
protected void onPostExecute(@NonNull BitmapWorkerResult result) {
if (result.mBitmapWorkerException == null) {
mBitmapLoadCallback.onBitmapLoaded(result.mBitmapResult, result.mExifInfo, mInputUri.getPath(), (mOutputUri == null) ? null : mOutputUri.getPath());
} else {
mBitmapLoadCallback.onFailure(result.mBitmapWorkerException);
}
} When doing this @Override
protected void onPostExecute(@Nullable Throwable t) {
if (mCropCallback != null) {
if (t == null) {
Uri uri = Uri.fromFile(new File(mImageOutputPath));
mCropCallback.onBitmapCropped(uri, cropOffsetX, cropOffsetY, mCroppedImageWidth, mCroppedImageHeight);
} else {
mCropCallback.onCropFailure(t);
}
}
} Inside the copyFile method of the BitmapLoadTask class we have the same problem: outputStream = new FileOutputStream(new File(outputUri.getPath())); So I think it is really a bug. When using SAF the uCrop should pass along the Uri and not try to rebuild one with the path string. I've forked the repository and I will try to make some adjusts in order to try to correct this. I can share this work or discuss it better if some uCrop developer thinks it can be useful but as I'm new to this project source I may be missing something. |
I have made the corrections and opened a pull request #732. For the "I wanna be an alpha tester" kind of person or if you're desperate or just curiousIf someone with the same error wants to try this in advance as an alpha tester and maybe help validate my work, you can do this by pointing your source code dependence to my pull request by changing this line of your build.gradle file: implementation 'com.github.yalantis:ucrop:2.2.6-native' to this: implementation 'com.github.yalantis:ucrop:PR732-SNAPSHOT' Success or failure reports will be appreciated. Thanks in advance! 😄 👍 |
This works perfectly indeed. It fixes the issue. I have the same issue with 'content:' files, this fixes it, should be merged. I have created a simple example with the fix here -> https://github.com/codespair/CameraImageUCropTutorial |
Hi Fabio, your pull request works perfectly. Thank you |
I faced the same problem. The pictures I took with the camera were giving this error on Android 11 and above.
|
java.io.FileNotFoundException: /external/images/media/66991: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileOutputStream.(FileOutputStream.java:235)
at java.io.FileOutputStream.(FileOutputStream.java:186)
at com.yalantis.ucrop.task.BitmapLoadTask.copyFile(BitmapLoadTask.java:177)
at com.yalantis.ucrop.task.BitmapLoadTask.processInputUri(BitmapLoadTask.java:155)
at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:85)
at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:36)
at android.os.AsyncTask$3.call(AsyncTask.java:378)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7296)
at libcore.io.IoBridge.open(IoBridge.java:482)
at java.io.FileOutputStream.(FileOutputStream.java:235)
at java.io.FileOutputStream.(FileOutputStream.java:186)
at com.yalantis.ucrop.task.BitmapLoadTask.copyFile(BitmapLoadTask.java:177)
at com.yalantis.ucrop.task.BitmapLoadTask.processInputUri(BitmapLoadTask.java:155)
at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:85)
at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:36)
at android.os.AsyncTask$3.call(AsyncTask.java:378)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
The text was updated successfully, but these errors were encountered: