How to use the @react-native-community/cameraroll.saveToCameraRoll function in @react-native-community/cameraroll

To help you get started, we’ve selected a few @react-native-community/cameraroll 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 mattermost / mattermost-mobile / app / screens / image_preview / downloader.ios.js View on Github external
this.downloadTask = RNFetchBlob.config(options).fetch('GET', imageUrl);
            this.downloadTask.progress((received, total) => {
                const progress = (received / total) * 100;
                if (this.mounted) {
                    this.setState({
                        progress,
                        started: true,
                    });
                }
            });

            const res = await this.downloadTask;
            let path = res.path();

            if (saveToCameraRoll) {
                path = await CameraRoll.saveToCameraRoll(path, 'photo'); /* eslint-disable-line require-atomic-updates */
            }

            if (this.mounted) {
                this.setState({
                    progress: 100,
                }, async () => {
                    if (this.state.didCancel) {
                        try {
                            await RNFetchBlob.fs.unlink(path);
                        } finally {
                            this.downloadDidCancel();
                        }
                    } else {
                        this.props.onDownloadSuccess();
                    }
                });
github keybase / client / shared / actions / platform-specific / index.native.tsx View on Github external
export async function saveAttachmentToCameraRoll(filePath: string, mimeType: string): Promise {
  const fileURL = 'file://' + filePath
  const saveType = mimeType.startsWith('video') ? 'video' : 'photo'
  const logPrefix = '[saveAttachmentToCameraRoll] '
  try {
    await requestPermissionsToWrite()
    logger.info(logPrefix + `Attempting to save as ${saveType}`)
    await CameraRoll.saveToCameraRoll(fileURL, saveType)
    logger.info(logPrefix + 'Success')
  } catch (e) {
    // This can fail if the user backgrounds too quickly, so throw up a local notification
    // just in case to get their attention.
    PushNotifications.localNotification({
      message: `Failed to save ${saveType} to camera roll`,
    })
    logger.debug(logPrefix + 'failed to save: ' + e)
    throw e
  } finally {
    require('rn-fetch-blob').default.fs.unlink(filePath)
  }
}
github iyegoroff / react-native-image-filter-kit / examples / ImageExtraction / src / App.tsx View on Github external
const saveImage = (uri: string) => (
  CameraRoll.saveToCameraRoll(uri, 'photo')
)
github alphasp / pxview / src / components / HOC / enhanceSaveImage.js View on Github external
workId,
          workTitle,
          workType,
          saveImageSettings,
          imageIndex || index,
        );
        try {
          const res = await RNFetchBlob.config({
            path: `${imagesDir}/${fileName}`,
          }).fetch('GET', url, {
            referer: 'http://www.pixiv.net',
          });
          const filePath = res.path();
          if (Platform.OS === 'ios') {
            try {
              await CameraRoll.saveToCameraRoll(filePath);
              this.showToast(
                i18n.formatString(i18n.saveImageSuccess, fileName),
              );
            } catch (err) {
              this.showToast(i18n.formatString(i18n.saveImageError, fileName));
            }
          } else if (Platform.OS === 'android') {
            this.showToast(i18n.formatString(i18n.saveImageSuccess, fileName));
            try {
              await RNFetchBlob.fs.scanFile([{ path: filePath }]);
            } catch (err) {}
          }
        } catch (err) {
          this.showToast(i18n.formatString(i18n.saveImageError, fileName));
        }
      });
github keybase / client / shared / actions / platform-specific / index.native.tsx View on Github external
export const saveAttachmentDialog = async (filePath: string) => {
  const goodPath = filePath
  logger.debug('saveAttachment: ', goodPath)
  await requestPermissionsToWrite()
  return CameraRoll.saveToCameraRoll(goodPath)
}
github esteemapp / esteem-mobile / src / components / postElements / body / view / postBodyView.js View on Github external
const _saveImage = async uri => {
    try {
      if (Platform.OS === 'android') {
        await checkAndroidPermission();
        uri = `file://${await _downloadImage(uri)}`;
      }
      CameraRoll.saveToCameraRoll(uri)
        .then(res => {
          Alert.alert(
            intl.formatMessage({ id: 'alert.success' }),
            intl.formatMessage({ id: 'post.image_saved' }),
            [{ text: 'OK' }],
            { cancelable: false },
          );
        })
        .catch(error => {
          Alert.alert(
            intl.formatMessage({ id: 'post.image_saved_error' }),
            error.message,
            [{ text: 'OK' }],
            {
              cancelable: false,
            },
github mattermost / mattermost-mobile / app / screens / image_preview / downloader.ios.js View on Github external
}).start(async () => {
            await CameraRoll.saveToCameraRoll(videoPath, 'video');
            this.props.onDownloadSuccess();
            InteractionManager.runAfterInteractions(() => {
                this.setState({force: false, isVideo: false});
            });
        });
    };
github CodeRabbitYu / ShiTu / app / store / PublicStore.js View on Github external
saveImageWithIOS = async (url: string) => {
    try {
      await CameraRoll.saveToCameraRoll(url, 'photo');
      this.showToast('保存成功');
    } catch (e) {
      this.showToast('保存失败');
    }
  };

@react-native-community/cameraroll

React Native Camera Roll for iOS & Android

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis