From d0356476c06047bbe0e7049d68c6656f240d9f7a Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Mon, 17 Jan 2022 12:33:36 +0200 Subject: [PATCH] Fix document upload on Android --- src/components/AttachmentPicker/index.native.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index 0b56964d4eea..15cd8f4bba52 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -71,6 +71,13 @@ function getDataForUpload(fileData) { size: fileData.fileSize || fileData.size, }; + // When the URI is lacking uri scheme - file upload would fail + // Prefixing the uri with `file://` fixes attachment upload on Android + const hasScheme = /^.+:\/\//.test(fileResult.uri); + if (!hasScheme) { + fileResult.uri = `file://${fileResult.uri}`; + } + if (fileResult.size) { return Promise.resolve(fileResult); } @@ -198,7 +205,6 @@ class AttachmentPicker extends Component { return reject(new Error(`Error during attachment selection: ${response.errorMessage}`)); } - // Resolve with the first (and only) selected file return resolve(response.assets); }); });