# Resolving issue: failed to attach an image in android

**URL:** <https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356>\
**Category:** Development\
**Created:** [6 March 2021 08:29 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356 "2021-03-06T08:29:10Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [6 March 2021 08:29 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/1 "2021-03-06T08:29:11Z")

</div>

Hi, I am exploring the mobile-App of Joplin  
and seen some similar issues in android

> <https://github.com/laurent22/joplin/issues/3981#issue-729025983>
>
> Environment
> Joplin version: 1.2.6 (PlayStore)
> Platform: Android
> OS specifics: Android 11 (Stock; Pixel4)
> Steps to reproduce
> Create a new note
> Attach an image from the gallery (in...

and this one also

> <https://github.com/react-native-image-picker/react-native-image-picker/issues/995#issue-387418401>
>
> Description
> We are using MobileIron Android-AppConnect to wrap the app. The app crashies upon finishing to pick an image.
> java.lang.IllegalArgumentException: column '\_data' does...

I think there is no problem with `@react-native-file-picker` , problem is the Storage Permission.  
File -picker behaves bit different in every android version , in some versions it asks for permission before going to pick file but in other(like android 10) it is not ask for storage permission for only file picker.

in my case- I use OnePlus6 (android 10) , as the guideline of Android, we don't have to ask permission for android default system file picker, but if we want to pick file from other built in apps (like Gallery etc...) then we need granted permission to access storage  
People generally use gallery for pick photos.  
I recreate this issue in android 9,10 and 11.

let see what happens when I recreate this issue in android 10

first I clicked on attach

 ![attachFilePopup](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/2X/2/2abf15a27ead919394b9647274e423680b9cdc72.jpeg)  
it pops up two options ,  
then I click on attach file - it opens File picker without asking permission  
and then I choose gallery for pic file  
 ![optionsInFilePicker](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/2X/8/8b056967a218b3afa8ef828be324a8e6f3cc8398.jpeg)  
then i choose photo from gallery and it showed me an error  
-Permission denied  
 ![clickOnImage](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/2X/c/c52328676c71cb3b6cd5bfa5004bc222239b2da3.jpeg)  
and after clicked on `ok` it did't ask me for storage permission.

then i went in app info and manually allowed storage permission and then it successfully attached photo in note.  
in any case Joplin did not crash.  
but it can crash in older version of androids.

so , we can resolve this issue by adding runtime storage permission in `Note.js` file it generalizes for all device, when user click on attach file it first verify the storage permission before going forward!!! this way we don't have to depend on file picker to ask permission.

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [6 March 2021 12:57 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/2 "2021-03-06T12:57:43Z")

</div>

Did a quick test but could not reproduce the error, though I may have granted the permissions earlier.  
In any case, I think the correct way to do this is to use URI permissions, this way Joplin does not need to request anything to read the file. To do this however it must read the data via the `ContentResolver` rather than trying to read it as a file on storage.

So in summary: yes, requesting storage permissions will work (until Android 11, I think) but it's not the best way.

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [6 March 2021 16:57 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/3 "2021-03-06T16:57:58Z")

</div>

if u want to recreate issue go to app setting and deny media and files permission.(this issue is not in all androids)

you are right , in latest android 12 and 11, we must use `ContentResolver` API to **Retrieve data** it makes Joplin more data secure app, no additional permission needed. and for older android Sdks we can Add Permission check.  
currently I don't know how to retrieve data by URI with Native APIs . but I worked on a project in past in which I use `Media Store` and `Content Resolver` APIs in android to Retrieve music files and there thumbnail(using bitmap decode).

Please also tell me about Search in Joplin android app, it is working too bad in my android 10.

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [6 March 2021 18:14 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/4 "2021-03-06T18:14:29Z")

</div>

> [@Amarpsp10](#):
>
> how to retrieve data by URI with Native APIs

I think it's [ContentResolver.openInputStream](https://developer.android.com/reference/android/content/ContentResolver#openInputStream(android.net.Uri))

> [@Amarpsp10](#):
>
> Please also tell me about Search in Joplin android app, it is working too bad in my android 10.

I do not know anything about it.

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [7 March 2021 11:52 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/5 "2021-03-07T11:52:03Z")

</div>

@Amarpsp10 if you're interested in fixing this looks like the best way forward is to use the `copyTo` option that you can pass to `react-native-document-picker` to copy the file to Joplin's cache or files dir.  
And then just rename it to whatever is needed for Joplin - since the file will be in Joplin's own dir, renaming it should not require any special access permissions.

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [7 March 2021 12:16 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/6 "2021-03-07T12:16:53Z")

</div>

@roman_r_m yes , trying to fixing it, I will use this Method 👍 👍 👍

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [8 March 2021 03:31 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/7 "2021-03-08T03:31:05Z")

</div>

@roman_r_m sorry to say, but App is already doing same thing, It copy the chosen file in user data(Joplin's own dir) and then proceed next, means there is another problem, but yeah I learnt working of `Document Picker`,

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [8 March 2021 07:59 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/8 "2021-03-08T07:59:50Z")

</div>

It does copy the file, sure, just not how, I think, it should do it. I'll take a look later.

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [8 March 2021 08:09 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/9 "2021-03-08T08:09:35Z")

</div>

@roman_r_m I saw this statement after picking file `copy(localFilePath, targetPath);`  
and here `localFilePath` is Uri of picked file. and  
`const targetPath = Resource_1.default.fullPath(resource);`  
where  
`const Resource_1 = require("@joplin/lib/models/Resource");`  
if you get something please tell

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [8 March 2021 21:08 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/10 "2021-03-08T21:08:22Z")

</div>

So I have tried to reproduce the issue from your original post and could not (I am using the emulator bundled with Android studio). Even without storage permissions I can share pictures both from the stock gallery app and from a random 3rd party gallery I've installed from apkmirror.

UPD  
Also tried Android 11 - same result.

I think I know how to fix it but without being able to test my changes I am not sure what I can do here.

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [9 March 2021 09:49 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/11 "2021-03-09T09:49:41Z")

</div>

> [@roman\_r\_m](#):
>
> tried to reproduce the issue from your original post and could not

really complex situation,

On GITHUB, Joplin mobile app have many Issues, in most of them I'm not able to reproduce.

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [9 March 2021 11:43 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/12 "2021-03-09T11:43:16Z")

</div>

If you, instead of attaching, open that gallery app and share an image to Joplin, does it work for you?

And can you also confirm the exact name of yout gallery app? Maybe I can try installing it and see if it changes anything.

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [9 March 2021 12:15 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/13 "2021-03-09T12:15:45Z")

</div>

> [@roman\_r\_m](#):
>
> If you, instead of attaching, open that gallery app and share an image to Joplin, does it work for you?

yes , working

> [@roman\_r\_m](#):
>
> confirm the exact name of yout gallery app

`OnePlus Gallery` in built in my phone

have you reproduce issue in your real device with android 10?  
because different mobiles have different "Security Patches".  
one thing more I saw, if we turn on our Developer options then device reduce its security. and also give some diff results

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [9 March 2021 12:19 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/14 "2021-03-09T12:19:26Z")

</div>

> [@Amarpsp10](#):
>
> have you reproduce issue in your real device with android 10?

I do not have a device with Android 10.

> [@Amarpsp10](#):
>
> yes , working

This is quite strange - the logic in both is very similar, in fact, sharing uses the same JS code as attaching, it's only the native side that is different.

Can you try the latest version of `react-native-document-picker`?

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [9 March 2021 13:57 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/15 "2021-03-09T13:57:06Z")

</div>

> [@roman\_r\_m](#):
>
> If you, instead of attaching, open that gallery app and share an image to Joplin, does it work for you?

sorry make a correction , when i share the image to Joplin from gallery it asks for permission , I forgot to reset permissions

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [9 March 2021 14:00 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/16 "2021-03-09T14:00:28Z")

</div>

Right. This makes sense, with permissions it can just read the file off the storage rather than use the URI provided.

I am not sure if there's an issue at all here - the user just need to provide read permissions and everything works. It's not ideal, and it might break in Android 11 but seems fine for now.

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [9 March 2021 14:07 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/17 "2021-03-09T14:07:03Z")

</div>

yes off topic, but I am going to work on a Backlog Feature `Search in Note`, this feature is still pending in mobile app.  
I am not getting a good issue for contribution

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [9 March 2021 14:15 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/18 "2021-03-09T14:15:04Z")

</div>

Yes, looks like most issues are with desktop app, probably because it has more functions. And most issues on mobile seem to be related to sync.  
If you prefer working on mobile, there are a few choices still:

- [Infinite vibration on to-do reminder notification · Issue #4086 · laurent22/joplin · GitHub](https://github.com/laurent22/joplin/issues/4086)
- [Menu is jumping around on synchronization · Issue #3725 · laurent22/joplin · GitHub](https://github.com/laurent22/joplin/issues/3725)
- [Android, Mobile: When I use mermaid on Android the nodes are too small and the text is not being fully displayed · Issue #4603 · laurent22/joplin · GitHub](https://github.com/laurent22/joplin/issues/4603)
- [[Feature request] Add Sync only on Wi-Fi option (mobile) · Issue #720 · laurent22/joplin · GitHub](https://github.com/laurent22/joplin/issues/720) (not an issue so better check with Laurent on this)

---

<div class="post-metadata">

**Author:** ![Amarpsp10](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/amarpsp10/32/7473_2.png) [@Amarpsp10](https://discourse.joplinapp.org/u/Amarpsp10)\
**Post date:** [9 March 2021 14:18 UTC](https://discourse.joplinapp.org/t/resolving-issue-failed-to-attach-an-image-in-android/15356/19 "2021-03-09T14:18:14Z")

</div>

thanks for sharing
