How to use the rn-fetch-blob.wrap function in rn-fetch-blob

To help you get started, we’ve selected a few rn-fetch-blob 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 uport-project / uport-mobile / lib / utilities / ipfs.js View on Github external
export function* addImage ({uri, data}) {
  // console.log(`ipfs.addImage`)
  // console.log(uri)

  const file = Platform.OS === 'ios' ? uri.replace('file://', '') : uri
  return yield call(addFile, {name: 'file', filename: 'avatar.jpg', type: 'image/jpeg', data: RNFetchBlob.wrap(file)})
}
github blefebvre / react-native-sqlite-demo / src / sync / dropbox / DropboxDatabaseSync.ts View on Github external
): Promise {
    console.log(
      `[Dropbox backup] UPLOADING local file [${localFilePath}] to remote file [${dropboxFilePath}]!`
    );
    return RNFetchBlob.fetch(
      "POST",
      DROPBOX.UPLOAD_URL,
      {
        Authorization: `Bearer ${dropboxAccessToken}`,
        "Content-Type": "application/octet-stream",
        "Dropbox-API-Arg": JSON.stringify({
          path: dropboxFilePath,
          mode: "overwrite"
        })
      },
      RNFetchBlob.wrap(localFilePath)
    ).then((fetchBlobResponse: any) => {
      console.log("[Dropbox backup] UPLOAD response!", fetchBlobResponse);
      // Ensure we have `data` and a 200 response
      if (
        fetchBlobResponse.data &&
        fetchBlobResponse.respInfo &&
        fetchBlobResponse.respInfo.status === 200
      ) {
        console.log("[Dropbox backup] UPLOAD SUCCESS!");
        // Record `client_modified` timestamp
        const responseData = JSON.parse(fetchBlobResponse.data);
        const clientModifiedTimestamp =
          responseData[DROPBOX.CLIENT_MODIFIED_TIMESTAMP_KEY];
        console.log(
          "[Dropbox backup] logging most recent backup timestamp as: " +
            clientModifiedTimestamp
github CodeRabbitYu / ShiTu / app / store / ShiTu / ShiTuStore.js View on Github external
const token = tokenData.data.token;
    const key = tokenData.data.key;
    const PATH = iOS ? response.uri.replace('file:///', '') : response.uri;
    const params = [
      {
        name: 'token',
        data: token
      },
      {
        name: 'key',
        data: key
      },
      {
        name: 'file',
        filename: 'file',
        data: RNFetchBlob.wrap(PATH)
      }
    ];

    console.log('params', params);

    return await upLoadImage(params);
  };
github pjay79 / PhotosApp / app / screens / PhotosScreen.js View on Github external
uploadPhoto = async () => {
    const { photos, index } = this.state;
    if (index !== null) {
      const { uri } = photos[index].node.image;
      const filenameiOS = photos[index].node.image.filename;
      const filenameAndroid = await RNFetchBlob.wrap(uri);
      this.uploadPhotoToS3(uri, Platform.OS === 'ios' ? filenameiOS : filenameAndroid);
    } else {
      Alert.alert(
        'Oops',
        'Please select a photo',
        [{ text: 'OK', onPress: () => console.log('OK Pressed') }],
        { cancelable: false },
      );
    }
  };
github mattermost / mattermost-mobile / app / actions / views / voice.js View on Github external
async function uploadVoiceMessage(file, post) {
    const fileData = buildFileUploadData(file);

    const headers = {
        Authorization: `Bearer ${Client4.getToken()}`,
        'X-Requested-With': 'XMLHttpRequest',
        'Content-Type': 'multipart/form-data',
        'X-CSRF-Token': Client4.csrf,
    };

    const fileInfo = {
        name: 'files',
        filename: encodeHeaderURIStringToUTF8(fileData.name),
        data: RNFetchBlob.wrap(file.localPath.replace('file://', '')),
        type: fileData.type,
    };

    const data = [
        {name: 'channel_id', data: post.channel_id},
        {name: 'client_ids', data: file.clientId},
        fileInfo,
    ];

    Client4.trackEvent('api', 'api_files_upload');

    const certificate = await mattermostBucket.getPreference('cert');
    const options = {
        timeout: 10000,
        certificate,
    };
github mattermost / mattermost-mobile / app / screens / edit_profile / edit_profile.js View on Github external
uploadProfileImage = async () => {
        const {profileImage} = this.state;
        const {currentUser} = this.props;
        const fileData = buildFileUploadData(profileImage);

        const headers = {
            Authorization: `Bearer ${Client4.getToken()}`,
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'multipart/form-data',
            'X-CSRF-Token': Client4.csrf,
        };

        const fileInfo = {
            name: 'image',
            filename: encodeHeaderURIStringToUTF8(fileData.name),
            data: RNFetchBlob.wrap(profileImage.uri.replace('file://', '')),
            type: fileData.type,
        };

        const certificate = await mattermostBucket.getPreference('cert');
        const options = {
            timeout: 10000,
            certificate,
        };

        return RNFetchBlob.config(options).fetch('POST', `${Client4.getUserRoute(currentUser.id)}/image`, headers, [fileInfo]);
    };
github mattermost / mattermost-mobile / app / components / file_upload_preview / file_upload_item / file_upload_item.js View on Github external
uploadFile = async (file) => {
        const {channelId} = this.props;
        const fileData = buildFileUploadData(file);

        const headers = {
            Authorization: `Bearer ${Client4.getToken()}`,
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'multipart/form-data',
            'X-CSRF-Token': Client4.csrf,
        };

        const fileInfo = {
            name: 'files',
            filename: encodeHeaderURIStringToUTF8(fileData.name),
            data: RNFetchBlob.wrap(file.localPath.replace('file://', '')),
            type: fileData.type,
        };

        const data = [
            {name: 'channel_id', data: channelId},
            {name: 'client_ids', data: file.clientId},
            fileInfo,
        ];

        Client4.trackEvent('api', 'api_files_upload');

        const certificate = await mattermostBucket.getPreference('cert');
        const options = {
            timeout: 10000,
            certificate,
        };