FileError {code: 1, message: "NOT_FOUND_ERR"}

Hello! I have a problem when I try to use File Pluging’s moveFile method, I get this error.
FileError {code: 1, message: “NOT_FOUND_ERR”}
The strange thing is that the emulator works fine, but when I use it on the real device it doesn’t work. Please, I need someone to help me. I’ve been with this problem for two days. Thank you.

I share my code.

After taking a photo, I make it go through the renameFile method.

 getVideoFromCamera() {
        const videoUrlBehaviorSubject: BehaviorSubject<string> = new BehaviorSubject<string>('');

        this.mediaCapture.captureVideo({ limit: 1, duration: 60, quality: 0.5 })
            .then((data: MediaFile[]) => {
                const newFileNamePrefix = 'video-' + this.authProvider.getLoggedUserId();

                this.fileService.renameFile(data[0].fullPath, newFileNamePrefix)
                    .then((entry) => {
                        let videoUrl = entry.nativeURL;
                        if (this.platform.is('ios')) {
                            videoUrl = videoUrl.replace(/^file:\/\//, '');
                        }
                        videoUrlBehaviorSubject.next(videoUrl);
                    })
                    .catch((err) => {
                        videoUrlBehaviorSubject.error(err);

                    });
            }).catch((err: CaptureError) => {
                if (err.code !== '3') {
                    videoUrlBehaviorSubject.error(err);
                }
            });

        return videoUrlBehaviorSubject.asObservable();
    }
public async renameFile(fileName: string, newFileNamePrefix: string): Promise<Entry> {
        let filePath = fileName.substr(0, fileName.lastIndexOf('/') + 1);
        if (this.platform.is('ios') && !filePath.startsWith('file://')) {
            filePath = 'file://' + filePath;
        }

        const oldFileName = fileName.substring(fileName.lastIndexOf('/') + 1);
        const newFileName: string = this.getUserFileName(fileName, newFileNamePrefix);

        return this.file.moveFile(filePath, oldFileName, filePath, newFileName);
    }

When the this.file.moveFile method is executed it throws the error.

I get very nervous when I see code that manipulates either (a) dates or (b) URLs as strings. I try to do my best to treat both of those things like black boxes, only to be passed around to dedicated libraries whose job it is to manage them.

So is there any way you can rewrite this code without any of the munging around with the guts of URLs? (Bonus points for also getting rid of stuff intended only to execute on iOS). That just seems like a huge maintenance nightmare, and eliminating it may expose the proximate problem as well.

Thanks for answering, the code is not mine, I am migrated from ionic 3 to 5. In the end I did a refactoring of that and I was able to solve it. Thank you very much.

Hello :slight_smile: Would you have the refactored code that solved your issue ? a
I’m struggling with this issue, I have a file entry for the file captured but impossible to get my “hands” on it. When I create a blob the file is “empty”.

Thanks !

Hi, I am also suffering from this error.

Hi, I finally removed the fileService part and the name manipulation. My code looks like this:

getVideoFromCamera() {
        const videoUrlBehaviorSubject: BehaviorSubject<string> = new BehaviorSubject<string>('');

        this.mediaCapture.captureVideo({ limit: 1, duration: 60, quality: 0.5 })
            .then((data: MediaFile[]) => {
                videoUrlBehaviorSubject.next(data[0].fullPath);
            }).catch((err: CaptureError) => {
                if (err.code !== '3') {
                    videoUrlBehaviorSubject.error('Error');
                }
            });

        return videoUrlBehaviorSubject.asObservable();
}

That’s an improvement, but there are still some aspects that I would not consider particularly idiomatic. I would structure it more like so:

getVideoFromCamera(): Observable<string> {
  return from(this.mediaCapture.captureVideo({ limit: 1, duration: 60, quality: 0.5 })).pipe(
    map(mcrv => mcrv[0].fullPath));
}

Subjects are designed to be long-lived.
asObservable isn’t ever really needed.
Always declare return value types for every function you write.
The from operator mogrifies many things (including a Promise) into an Observable.