How to use the react-native-fs.TemporaryDirectoryPath function in react-native-fs

To help you get started, we’ve selected a few react-native-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github textileio / photos / App / Services / Photos.js View on Github external
}
          photos.push(photo)
          cursor = photo.pageInfo.end_cursor
          hasNextPage = photo.pageInfo.has_next_page
        }
        for (const photo of photos) {
          // assets-library://asset/asset.JPG?id=FA830DD9-67E7-48ED-BE29-CB4343340D1F&ext=JPG
          var path = photo.node.image.uri
          if (path.includes("assets-library://")) {
            var regex = /[?&]([^=#]+)=([^&#]*)/g,
                params = {},
                match;
            while (match = regex.exec(photo.node.image.uri)) {
              params[match[1]] = match[2];
            }
            path = RNFS.TemporaryDirectoryPath + params.id + '.' + params.ext
            const dest = await RNFS.copyAssetsFileIOS(photo.node.image.uri, path, 0, 0)
          }
          console.log("PINNING PHOTO:", path)
          const hash = await IPFS.addImageAtPath(path)
          console.log("PINNED", hash)
        }
        if (photos.length > 0) {
          const cursor = photos[0].pageInfo.end_cursor
          await AsyncStorage.setItem("latestPhotoQueried", cursor)
        }
      }
    } catch(error) {
      console.log("ERROR QUERING PHOTOS:", error)
    }
  }
github berty / berty / js / packages / components / chat / file-uploads / GallerySection.tsx View on Github external
const getUploadableURI = async (item: beapi.messenger.IMedia) => {
		if (Platform.OS === 'android') {
			return item.uri
		}
		// Workaround to get uploadable uri from ios
		const destination = `${RNFS.TemporaryDirectoryPath}${item.filename}`
		try {
			let absolutePath = item.uri && (await RNFS.copyAssetsFileIOS(item.uri, destination, 0, 0))
			setTimeout(() => RNFS.unlink(destination), 10000)
			return absolutePath
		} catch (error) {
			console.log(error)
		}
	}
github iotaledger / trinity-wallet / src / mobile / containers / PaperWallet.js View on Github external
this.props.navigator.pop({
            navigatorStyle: {
                navBarHidden: true,
                navBarTransparent: true,
                screenBackgroundColor: body.bg,
                drawUnderStatusBar: true,
                statusBarColor: body.bg,
            },
            animated: false,
        });
        if (this.state.pressedPrint) {
            RNFS.unlink(qrPath);

            // Doesn't convert to PDF for android.
            if (isIOS) {
                Promise.resolve(RNFS.readDir(RNFS.TemporaryDirectoryPath)).then((item) =>
                    item.forEach((i) => RNFS.unlink(i.path)),
                );
            }
        }
    }
github berty / berty / js / packages / components / modals / ForwardToBertyContactModal.tsx View on Github external
}> = ({ image, onClose }) => {
	const tempPath = `${RNFS.TemporaryDirectoryPath}/${image.filename}`

	const [{ color, border, padding, margin }, { windowHeight }] = useStyles()
	const { t }: { t: any } = useTranslation()
	const conversations: any[] = useSortedConversationList()
	const ctx = useMsgrContext()
	const client = useClient()

	useEffect(() => {
		RNFS.writeFile(tempPath, image.uri.split('base64,')[1], 'base64')
			.then((res) => console.log(res))
			.catch((err) => console.log(err))
	}, [image, tempPath])

	const handleClose = async () => {
		try {
			await RNFS.unlink(tempPath)
github berty / berty / js / packages / store / services.tsx View on Github external
export const exportAccountToFile = async () => {
	const messengerMiddlewares = middleware.chain(
		__DEV__ ? middleware.logger.create('MESSENGER') : null,
	)

	const messengerClient = Service(beapi.messenger.MessengerService, rpcBridge, messengerMiddlewares)

	const outFile = RNFS.TemporaryDirectoryPath + 'berty-' + String(Date.now()).slice(-4) + '.tar'

	const outputStream = await RNFetchBlob.fs.writeStream(outFile, 'base64')
	await messengerClient
		.instanceExportData({})
		.then((stream) => {
			stream.onMessage(async (res) => {
				if (!res || !res.exportedData) {
					return
				}

				await outputStream.write(Buffer.from(res.exportedData).toString('base64'))
			})
			return stream.start()
		})
		.then(async () => {
			await outputStream.close()
github GantMan / nicornot / NicOrNotApp / src / lib / fetchModel.js View on Github external
const fetchModel = async modelURL => {
  const modelName = modelURL.match(/([^\/]+)(?=\.\w+$)/)[0]
  const mlc = modelName + '.mlmodelc'
  const ml = modelName + '.mlmodel'
  const compiledPath = RNFS.DocumentDirectoryPath + '/' + mlc
  if (await RNFS.exists(compiledPath)) {
    return compiledPath
  }
  const toFile = RNFS.TemporaryDirectoryPath + ml
  if (!(await RNFS.exists(toFile))) {
    const { promise, _jobId } = RNFS.downloadFile({
      fromUrl: modelURL,
      toFile: toFile
    })
    await promise
  }
  const tempPath = await compileModel(toFile)
  await RNFS.moveFile(tempPath, compiledPath)
  return 'file://' + compiledPath
}