jibon57 / nativescript-mediafilepicker

A complete file picker solution for NativeScript
Apache License 2.0
51 stars 39 forks source link

CRITICAL - Uncaught TypeError: Cannot read property 'path' of null on video select #147

Open andrewm-mitchells opened 3 years ago

andrewm-mitchells commented 3 years ago

Describe the bug When selecting a video the app crashes with the error listed in the title. It seems to work on iOS 15 beta but crashes on 14.5 at least in simulator for me but couple of internal testers reported it crashed on them when used on an actual device.

To Reproduce Install the plugin, follow instructions in the plugin documentation, attempt to add a video when running test app in simulator.

Expected behavior Video selected with no errors and uploading process starts.

NativeScript Info(please run tns info):

✔ Getting NativeScript components versions information...
✔ Component nativescript has 8.0.2 version and is up to date.
⚠ Update available for component @nativescript/core. Your current version is 7.1.4 and the latest available version is 8.0.8.
⚠ Update available for component @nativescript/ios. Your current version is 7.1.0 and the latest available version is 8.0.0.
⚠ Update available for component @nativescript/android. Your current version is 7.0.1 and the latest available version is 8.0.0.

Sample Code(please provide minimum code to reproduce problem):

pickFile(type) {
    let mediafilepicker = new Mediafilepicker();

    const images = ["heic", "HEIC", "jpg", "JPG", "jpeg", "JPEG", "png", "PNG", "gif", "GIF"];
    const videos = ["mp4", "MP4", "mov", "MOV", "m4v", "M4V", "3gp", "3GP"];

    if (type === "photo") {
      let options: ImagePickerOptions = {
        android: {
          isCaptureMood: false, // if true then camera will open directly.
          isNeedCamera: false,
          maxNumberFiles: 10,
          isNeedFolderList: true
        }, ios: {
          isCaptureMood: false, // if true then camera will open directly.
          isNeedCamera: false,
          maxNumberFiles: 10
        }
      };

      mediafilepicker.openImagePicker(options);
    } else if (type === "video") {
      let options: VideoPickerOptions = {
        android: {
          isCaptureMood: false, // if true then camera will open directly.
          isNeedCamera: false,
          maxNumberFiles: 1,
          isNeedFolderList: true,
          maxDuration: 10,
        },
        ios: {
          isCaptureMood: false, // if true then camera will open directly.
          videoMaximumDuration: 10
        }
      };

      mediafilepicker.openVideoPicker(options);
    }

    mediafilepicker.on("getFiles", res => {
      this.zone.run(() => {
        let results = res.object.get('results');

        results.forEach(element => {
          const file = element.file;
          const name = file.substr(file.lastIndexOf("/") + 1);
          const mimeType = name.substr(name.lastIndexOf('.')+1);

          const image = images.some((r) => mimeType.indexOf(r) >= 0);
          const video = videos.some((r) => mimeType.indexOf(r) >= 0);

          if (image) {
            ImageSource.fromFile(file)
            .then(res => {
              const requestId = this.uuidv4();
              const img = res;

              this.images.push({
                processing: true,
                awsUrl: "",
                primary: false,
                requestId: requestId,
                photo: img,
                skus: []
              });

              const encodedImg = res.toBase64String("jpeg");

              this.initAWSRequest("image", encodedImg, requestId);
            })
            .catch((err) => {
              this.errorMessage = err;
            });
          } else if (video) {
            this.getPresignedUrl(file, mimeType);
          } else {
            // Unsupported file format alert
          }
        });
      });
    });

    // for iOS iCloud downloading status
    // mediafilepicker.on("exportStatus", function (res) {
      // let msg = res.object.get('msg');
      // console.log("Export status");
      // console.log(res);
      // console.log(msg);
    // });

    mediafilepicker.on("error", function (res) {
      let msg = res.object.get('msg');
      this.errorMessage = msg;
    });

    // mediafilepicker.on("cancel", function (res) {
      // let msg = res.object.get('msg');
      // console.log("Cancel");
      // console.log(res);
      // console.log(msg);
    // });
  }

Additional context

***** Fatal JavaScript exception - application has been terminated. *****
NativeScript encountered a fatal error: Uncaught TypeError: Cannot read property 'path' of null
at
picker.didSelectAssets(file: node_modules/nativescript-mediafilepicker/mediafilepicker.ios.js:141:0)
(CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Uncaught TypeError: Cannot read property 'path' of null
at
picker.didSelectAssets(file: node_modules/nativescript-mediafilepicker/mediafilepicker.ios.js:141:0)
', reason: '(null)'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010d902fba __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x000000010d7acff5 objc_exception_throw + 48
2   NativeScript                        0x0000000108e5b8f4 _ZN3tns21NativeScriptException15OnUncaughtErrorEN2v85LocalINS1_7MessageEEENS2_INS1_5ValueEEE + 914
3   NativeScript                        0x00000001092bbf65 _ZN2v88internal14MessageHandler25ReportMessageNoExceptionsEPNS0_7IsolateEPKNS0_15MessageLocationENS0_6HandleINS0_6ObjectEEENS_5LocalINS_5ValueEEE + 341
4   NativeScript                        0x00000001092bbdd4 _ZN2v88internal14MessageHandler13ReportMessageEPNS0_7IsolateEPKNS0_15MessageLocationENS0_6HandleINS0_15JSMessageObjectEEE + 884
5   NativeScript          <…>
andrewm-mitchells commented 3 years ago

It seems like the issue is isolated only to iCloud stored files. While it's crossed on the plugin docs page it doesn't seem to be working properly in the current version or I'm doing something wrong.

In iOS after selecting file you may not be able to use it directly. In this case you will need to copy that file in your app directory.

andrewm-mitchells commented 3 years ago

Looks like the plugin is deprecated and development on it is dead unfortunately. Going to be looking for alternatives.