{"id":7989,"date":"2023-05-31T11:06:01","date_gmt":"2023-05-31T11:06:01","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=7989"},"modified":"2023-07-27T08:43:13","modified_gmt":"2023-07-27T08:43:13","slug":"permission-denial-obtain-access-using-action-open-document","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/react-native\/permission-denial-obtain-access-using-action-open-document","title":{"rendered":"How to Get Access Content URI of a Document in Android"},"content":{"rendered":"<p>Whenever we pick up a document on an Android device from the document picker, it returns us a URI something like <mark>content:\/\/\/<\/mark><\/p>\n<p>Where is the content provider authority of the selected file and is the file path relative to the content provider&#8217;s root directory.<br \/>\nWhich is not a valid link if you use it to send over the API, for example, when you are uploading a file on <strong>Firebase Storage<\/strong>.<\/p>\n<p>To overcome this problem, we can use the <mark>copyTo: &#8216;documentDirectory&#8217;<\/mark> option in the DocumentPicker. It will copy the selected file into the app\u2019s document directory and return a URI pointing to the copied file in the document directory.<\/p>\n<p>Here is how to achieve this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let documents = await DocumentPicker.pickMultiple({\r\n        type: DocumentPicker.types.allFiles, \/\/You can mention all the file types required here\r\n        copyTo: 'documentDirectory',\r\n      });\r\n\r\ndocuments = documents.map(doc =&gt; ({\r\n        ...item,\r\n        fileCopyUri: `file:\/\/${decodeURIComponent(doc.fileCopyUri)}`,\r\n      }));<\/pre>\n<p>Using the above code snippet, the URI which gets returned will look something like<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">file:\/\/&lt;path&gt;<\/pre>\n<p>Where will be the path of the copied file in your app\u2019s document directory.<\/p>\n<p>The <mark>fileCopyUri<\/mark> property is created by appending <mark>`file:\/\/`<\/mark> before the copied file uri so it can have a format like<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">file:\/\/&lt;path&gt;<\/pre>\n<p>The <mark>decodeURIComponent<\/mark> function will decode any URI-encoded characters in the URI such as spaces or non-ASCII characters.<\/p>\n<p>For More Information: <a href=\"https:\/\/www.npmjs.com\/package\/react-native-document-picker\" target=\"_blank\" rel=\"noopener\">React Native Document Picker<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whenever we pick up a document on an Android device from the document picker, it returns us a URI something like content:\/\/\/ Where is the content provider authority of the selected file and is the file path relative to the content provider&#8217;s root directory. Which is not a valid link if you use it to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8347,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-7989","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-native"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/7989"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=7989"}],"version-history":[{"count":9,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/7989\/revisions"}],"predecessor-version":[{"id":7997,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/7989\/revisions\/7997"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/8347"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=7989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=7989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=7989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}