mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
download to external android path
This commit is contained in:
parent
e59f025e5a
commit
6b60098ff3
@ -1,10 +1,10 @@
|
|||||||
import { useState, useRef, useEffect, useContext } from 'react';
|
import { useState, useRef, useEffect, useContext } from 'react';
|
||||||
import { ConversationContext } from 'context/ConversationContext';
|
import { ConversationContext } from 'context/ConversationContext';
|
||||||
import { Image } from 'react-native';
|
import { Image } from 'react-native';
|
||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions, Platform } from 'react-native';
|
||||||
import { Platform } from 'react-native';
|
|
||||||
import RNFetchBlob from "rn-fetch-blob";
|
import RNFetchBlob from "rn-fetch-blob";
|
||||||
import Share from 'react-native-share';
|
import Share from 'react-native-share';
|
||||||
|
import RNFS from 'react-native-fs';
|
||||||
|
|
||||||
export function useBinaryAsset() {
|
export function useBinaryAsset() {
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ export function useBinaryAsset() {
|
|||||||
src = blob.path();
|
src = blob.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Platform.OS === 'iOS') {
|
||||||
const path = `${RNFetchBlob.fs.dirs.DocumentDir}`
|
const path = `${RNFetchBlob.fs.dirs.DocumentDir}`
|
||||||
const dst = `${path}/${label}.${extension.toLowerCase()}`
|
const dst = `${path}/${label}.${extension.toLowerCase()}`
|
||||||
if (RNFetchBlob.fs.exists(dst)) {
|
if (RNFetchBlob.fs.exists(dst)) {
|
||||||
@ -52,13 +53,17 @@ export function useBinaryAsset() {
|
|||||||
}
|
}
|
||||||
await RNFetchBlob.fs.mv(src, dst);
|
await RNFetchBlob.fs.mv(src, dst);
|
||||||
try {
|
try {
|
||||||
await Share.open({ url: dst, message: `${label}.${extension}`, subject: `${label}.${extension}` })
|
await Share.open({ url: dst })
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
RNFetchBlob.fs.unlink(dst);
|
RNFetchBlob.fs.unlink(dst);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const copy = RNFS.ExternalDirectoryPath + "/" label + "." + extension;
|
||||||
|
RNFS.copyFile(src, copy);
|
||||||
|
}
|
||||||
updateState({ downloading: false });
|
updateState({ downloading: false });
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user