Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

RNFetchBlob.fs.readFile method making the ui unresponsive for 2-3 seconds #712

Open
@developercode1

Description

@developercode1

I am trying to upload a image to an Amazon S3 Bucket. So I first use the react native fetch blob to read file from the react native camera cache using RNFetchBlob.fs.readFile method and then upload it to the S3 bucket. But the readFile method is taking too much time making the ui unresponsive for quite a few seconds. I also tried readStream method which didn't solve the problem either.

Below is the function trying to upload image

export async function readFile(filePath) {
   const data = await RNFetchBlob.fs.readFile(filePath, 'base64');
   return new Buffer(data, 'base64');
}

export const deleteFile = async (filePath) => {
     try {
	const exist = await RNFetchBlob.fs.exists(filePath)
	if (exist) {
	   await RNFetchBlob.fs.unlink(filePath)
	}
     } catch(err) {
          console.log("Error", err)
     }
}
async function uploadImage() {
  try {
     const buffer = await readFile(fileUri);
     const response = await Storage.put(key, buffer, { "contentType": "image/jpeg", "metaData": metaData 
  });
      if (response) {
	  store.dispatch(removeFromOfflineQueue(key));
 	  store.dispatch(uploadImageStatus(key, true));
	  await resizeImage(key, cleanUri, true);
      }
   } catch(err) {
          console.log("::UPLOAD ERR", err);
          store.dispatch(addToOfflineQueue(key, body, metaData)
      }
   }
}

So is there any way by which we can either reduce the lag time or run it in background so that it doesn't affects the UI?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions