How to use the expo-file-system.downloadAsync function in expo-file-system

To help you get started, we’ve selected a few expo-file-system 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 flow-typed / flow-typed / definitions / npm / expo-file-system_v4.x.x / flow_v0.69.0-v0.103.x / test_expo-file-system.js View on Github external
it('should raises an error when pass invalid arguments', () => {
    // $ExpectError: first argument is required
    downloadAsync();
    // $ExpectError: first argument must be a string
    downloadAsync(69);
    // $ExpectError: second argument must be a string
    downloadAsync('', 69);
    // $ExpectError: third argument must be an object
    downloadAsync('', '', 69);
    // $ExpectError: 'abc' is missing in options
    downloadAsync('', '', { abc: 'test' });
    downloadAsync('', '', {
      // $ExpectError: invalid value
      md5: 'need boolean',
    });
  });
});
github flow-typed / flow-typed / definitions / npm / expo-file-system_v4.x.x / flow_v0.69.0-v0.103.x / test_expo-file-system.js View on Github external
it('should passes when used properly', () => {
    downloadAsync('url', 'fileUri').then(result => {
      (result.uri: string);
      (result.status: number);
      (result.headers: { [string]: string });
      (result.md5: ?string);

      // $ExpectError: check any
      (result.uri: number);
    });

    downloadAsync('url', 'fileUri', { md5: false });
    downloadAsync('url', 'fileUri', { cache: false });
    downloadAsync('url', 'fileUri', { headers: { 'header-name': 'abc' } });
    downloadAsync('url', 'fileUri', {
      md5: false,
      cache: false,
      headers: { 'X-Auth': 'abc' },
    });
  });
github flow-typed / flow-typed / definitions / npm / expo-file-system_v4.x.x / flow_v0.69.0-v0.103.x / test_expo-file-system.js View on Github external
it('should raises an error when pass invalid arguments', () => {
    // $ExpectError: first argument is required
    downloadAsync();
    // $ExpectError: first argument must be a string
    downloadAsync(69);
    // $ExpectError: second argument must be a string
    downloadAsync('', 69);
    // $ExpectError: third argument must be an object
    downloadAsync('', '', 69);
    // $ExpectError: 'abc' is missing in options
    downloadAsync('', '', { abc: 'test' });
    downloadAsync('', '', {
      // $ExpectError: invalid value
      md5: 'need boolean',
    });
  });
});
github flow-typed / flow-typed / definitions / npm / expo-file-system_v4.x.x / flow_v0.69.0-v0.103.x / test_expo-file-system.js View on Github external
it('should passes when used properly', () => {
    downloadAsync('url', 'fileUri').then(result => {
      (result.uri: string);
      (result.status: number);
      (result.headers: { [string]: string });
      (result.md5: ?string);

      // $ExpectError: check any
      (result.uri: number);
    });

    downloadAsync('url', 'fileUri', { md5: false });
    downloadAsync('url', 'fileUri', { cache: false });
    downloadAsync('url', 'fileUri', { headers: { 'header-name': 'abc' } });
    downloadAsync('url', 'fileUri', {
      md5: false,
      cache: false,
      headers: { 'X-Auth': 'abc' },
github flow-typed / flow-typed / definitions / npm / expo-file-system_v4.x.x / flow_v0.69.0-v0.103.x / test_expo-file-system.js View on Github external
it('should raises an error when pass invalid arguments', () => {
    // $ExpectError: first argument is required
    downloadAsync();
    // $ExpectError: first argument must be a string
    downloadAsync(69);
    // $ExpectError: second argument must be a string
    downloadAsync('', 69);
    // $ExpectError: third argument must be an object
    downloadAsync('', '', 69);
    // $ExpectError: 'abc' is missing in options
    downloadAsync('', '', { abc: 'test' });
    downloadAsync('', '', {
      // $ExpectError: invalid value
      md5: 'need boolean',
    });
  });
});
github expo / expo / packages / expo-asset / src / Asset.ts View on Github external
async _downloadAsyncUnmanagedEnv(): Promise {
    // Bail out if it's already at a file URL because it's already available locally
    if (this.uri.startsWith('file://')) {
      this.localUri = this.uri;
      return;
    }

    const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${this.hash}.${this.type}`;
    // We don't check the FileSystem for an existing version of the asset and we
    // also don't perform an integrity check!
    await FileSystem.downloadAsync(this.uri, localUri);
    this.localUri = localUri;
  }
github expo / expo-asset-utils / src / fileInfoAsync.js View on Github external
} else if (isLocalUri(url)) {
    /// local image: we just need the hash
    let file = await resolveLocalFileAsync({ uri: url, name });
    if (!file) {
      file = await resolveLocalFileAsync({ uri: localUri, name });
      if (!file) {
        throw new Error(
          `expo-asset-utils: fileInfoAsync(): couldn't resolve md5 hash for local uri: ${url} or alternate: ${localUri}`
        );
        return null;
      }
    }
    return file;
  } else {
    /// remote image: download first
    const { uri, md5: hash } = await FileSystem.downloadAsync(url, localUri, {
      md5: true,
    });
    return { uri, name, hash };
  }
}
export default fileInfoAsync;
github brunon80 / expo-image-crop / example / manipulator / ImageManipulator.js View on Github external
Image.getSize(uri, async (width2, height2) => {
            let cropObj;
            ({ cropObj, imgWidth, imgHeight } = this.getCropBounds(imgWidth, width2, imgHeight, height2))

            if (cropObj.height > 0 && cropObj.width > 0) {
                let uriToCrop = uri
                if (this.isRemote) {
                    const response = await FileSystem.downloadAsync(
                        uri,
                        FileSystem.documentDirectory + 'image',
                    )
                    uriToCrop = response.uri
                }
                const { uri: uriCroped, base64 } = await this.crop(cropObj, uriToCrop)
                this.setState({
                    uri: uriCroped, base64, cropMode: false, processing: false,
                })
            }
        })
    }
github expo / expo / packages / expo-asset / build / Asset.js View on Github external
async _downloadAsyncManagedEnv() {
        const localUri = `${FileSystem.cacheDirectory}ExponentAsset-${this.hash}.${this.type}`;
        let { exists, md5 } = await FileSystem.getInfoAsync(localUri, {
            md5: true,
        });
        if (!exists || md5 !== this.hash) {
            ({ md5 } = await FileSystem.downloadAsync(this.uri, localUri, {
                md5: true,
            }));
            if (md5 !== this.hash) {
                throw new Error(`Downloaded file for asset '${this.name}.${this.type}' ` +
                    `Located at ${this.uri} ` +
                    `failed MD5 integrity check`);
            }
        }
        this.localUri = localUri;
    }
    async _downloadAsyncUnmanagedEnv() {