Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert the path to a blob or base64 on iOS? #84

Open
wijzijnweb opened this issue Jun 25, 2024 · 1 comment
Open

How to convert the path to a blob or base64 on iOS? #84

wijzijnweb opened this issue Jun 25, 2024 · 1 comment

Comments

@wijzijnweb
Copy link

wijzijnweb commented Jun 25, 2024

On iOS I cant seem to fetch or read the file using fetch or the capacitor filesystem.
File is always "Not found".

On Android it returns: result.videoFilePath
On iOS it returns: result.videoUrl (with file://)

This can't be fetched since it only supports http.
The filesystem also says it's not found.

Any idea on how to solve this?
I've tried:

 const result = await Filesystem.readFile({
            path: filePath,
            directory: FilesystemDirectory.Library, 
            encoding: Encoding.BASE64
        });

A normal fetch(result.videoUrl) won't work.

EDIT

This should work according to the capacitor docs:

const res = await CameraPreview.stopRecordVideo();

const base64 = await Filesystem.readFile({
        path: res.videoUrl
});

console.log(base64)

But this isn't working for me. File not found.

@wijzijnweb
Copy link
Author

func captureVideo() throws {
        guard let captureSession = self.captureSession, captureSession.isRunning else {
            throw CameraControllerError.captureSessionIsMissing
        }
        let path = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
        let identifier = UUID()
        let randomIdentifier = identifier.uuidString.replacingOccurrences(of: "-", with: "")
        let finalIdentifier = String(randomIdentifier.prefix(8))
        let fileName="cpcp_video_"+finalIdentifier+".mp4"
        let fileUrl = path.appendingPathComponent(fileName)
        try? FileManager.default.removeItem(at: fileUrl)
        // Start recording video
        // ...
        // Save the file URL for later use
        self.videoFileURL = fileUrl
    }

Not sure, but is the video deleted on capture?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant