Vydia / react-native-background-upload

Upload files in your React Native app even while it's backgrounded. Supports Android and iOS, including camera roll assets.
MIT License
720 stars 325 forks source link

Upload Finishes instantly #305

Open nodabasi opened 2 years ago

nodabasi commented 2 years ago

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?

BruceWind commented 3 months ago

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);
}