Untitled
unknown
plain_text
2 years ago
1.8 kB
6
Indexable
const downloadDocument = async () => { let permissions = null if (Platform.OS === "android") { permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync() if (!permissions.granted) { return } } const split = selectedDoc.split(".") const extension = split[split.length - 1] const title = hookDd.documents.find((item) => item.doc === selectedDoc).title const fileName = title const callback = (downloadProgress) => { const progress = downloadProgress.totalBytesWritten / downloadProgress.totalBytesExpectedToWrite } const downloadResumable = FileSystem.createDownloadResumable( `${IMAGE_PREFIX}${selectedDoc}`, FileSystem.documentDirectory + `${fileName}.${extension}`, {}, callback ) try { const { uri } = await downloadResumable.downloadAsync() if (Platform.OS === "android") { const types = { doc: "application/msword", docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", xls: "application/vnd.ms-excel", xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", pdf: "application/pdf", } await StorageAccessFramework.createFileAsync(permissions.directoryUri, `${fileName}.${extension}`, types[extension]) .then(async (r) => { const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 }) await FileSystem.writeAsStringAsync(r, base64, { encoding: FileSystem.EncodingType.Base64 }) }) .catch((e) => { // Sentry.Native.captureMessage("catch1") console.log(e, "E") }) } else { // Sentry.Native.captureMessage("else") await Sharing.Native.shareAsync(uri) } } catch (e) { // Sentry.Native.captureMessage("catch2") console.error(e) } }
Editor is loading...