react-native-background-upload icon indicating copy to clipboard operation
react-native-background-upload copied to clipboard

Upload Finishes instantly

Open nodabasi opened this issue 3 years ago • 1 comments

In my development, simulation upload works fine both in android and iOS both for videos and images. However, whenever I tried on the real devices it didn't work a new field creates in my db with 0 bytes. Also, uploads finishes instantly, for example for 1 min. long video(90-120mb) it also finishes instantly.

Can you help me with that?

nodabasi avatar Jun 20 '22 10:06 nodabasi

Hi, I faced the same issue. I found that param path need to begin with 'file://' on iOS platform.

My code is like:

export const uploadImage = async (
  filePath: string,
  remoteUrl: string
): Promise<string> => {
  const FPrefix = 'file://';

  let newFilePath = filePath.replace(FPrefix, '');

  // param @path here must begin with 'file://', but Android App dont need ths.
  const options: MultipartUploadOptions = {
    url: encodeURI(remoteUrl),
    path: encodeURI(Platform.OS === 'ios' ? (FPrefix + filePath) : newFilePath),
    method: 'POST',
    field: 'file',
    type: 'multipart'
  }

  return Upload.startUpload(options);
}

BruceWind avatar Mar 27 '24 06:03 BruceWind