{"id":8425,"date":"2023-07-31T10:48:34","date_gmt":"2023-07-31T10:48:34","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=8425"},"modified":"2023-07-31T10:48:34","modified_gmt":"2023-07-31T10:48:34","slug":"react-native-firebase-action-open-document","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/react-native\/react-native-firebase-action-open-document","title":{"rendered":"How do I overcome &#8220;Permission Denial&#8230;.Obtain Access Using ACTION_OPEN_DOCUMENT or Related APIs&#8221;?"},"content":{"rendered":"<p>Whenever we pick up a document on an Android device from the document picker, it returns us a URI something like<br \/>\n<mark>content:\/\/< authority >\/< path ><\/mark><br \/>\nWhere 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      }));\r\n<\/pre>\n<p>Using the above code snippet, the URI which gets returned will look something like<br \/>\n<mark>file:\/\/< path ><\/mark><br \/>\nWhere <path> 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 <mark>file:\/\/< path ><\/mark><\/p>\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\">NPMJS<\/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:\/\/< authority >\/< path > 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8426,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-8425","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\/8425"}],"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=8425"}],"version-history":[{"count":3,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8425\/revisions"}],"predecessor-version":[{"id":8429,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8425\/revisions\/8429"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/8426"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=8425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=8425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=8425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}