.then(exists => { if (!exists) { return RNFetchBlob.fs.mkdir(targetDir) .then (() => result) .catch(error => console.log(`storage.js prepareTargetPath ${error} ignored.`)) // TODO check already exist error .then (() => result) } else { return result; } })
share = () => { const image = this.state.photos[this.state.index].node.image.uri RNFetchBlob.fs.readFile(image, 'base64') .then((data) => { let shareOptions = { title: "React Native Share Example", message: "Check out this photo!", url: `data:image/jpg;base64,${data}`, subject: "Check out this photo!" } Share.open(shareOptions) .then((res) => console.log('res:', res)) .catch(err => console.log('err', err)) }) }
prepareTargetPath(storageUrl: String, path:String) : Promise { const { targetPath, targetDir } = this.pathAsDocumentsDirTarget(path); const result = { targetPath, storageUrl } // if needed create targetDir (otherwise we get an error fron RNFetchBlob) return RNFetchBlob.fs.exists(targetDir) .then(exists => { if (!exists) { return RNFetchBlob.fs.mkdir(targetDir) .then (() => result) .catch(error => console.log(`storage.js prepareTargetPath ${error} ignored.`)) // TODO check already exist error .then (() => result) } else { return result; } }) }
.then((resp) => { let file = resp.path() return RNFetchBlob.fs.readStream(resp.path(), 'utf8') })