I am trying to convert a video url which we can retrieve from an iOS device and convert it to BASE64 in ionic 3, but I am unable to achieve BASE64 url.
iOS Video URL: filePath = /var/mobile/Containers/Data/Application/3436A7EB-4684-4618-8125-3E6AE1645FCE/Documents/MUS_RA/1534429730643_capturedvideo.MOV
I tried the following code to convert the video URL to BASE64 by using the BASE64 cordova plugin but no luck
this.base64.encodeFile(filePath)
.then((base64String: string) => {
console.log("base64VideoChange");
resolve(base64String);
}, (err) => {
console.log("base64VideoNOTChange");
reject(err);
});
Note: I am using ionic 3. Please help.
Finally i resolved my issue by using ionic readAsDataURL:
Imports File plugin to app.module.ts
import { File, DirectoryEntry, FileEntry } from '@ionic-native/file';
In page.ts
import { File, DirectoryEntry, FileEntry } from '@ionic-native/file';
getBase64StringByFilePath(fileURL): Promise<string> {
return new Promise((resolve, reject) => {
let fileName = fileURL.substring(fileURL.lastIndexOf('/') + 1);
let filePath = fileURL.substring(0, fileURL.lastIndexOf("/") + 1);
this.file.readAsDataURL(filePath, fileName).then(
file64 => {
console.log(file64); //base64url...
resolve(file64);
}).catch(err => {
reject(err);
});
})
}
Imports File plugin to app.module.ts
.
import { Base64 } from '@ionic-native/base64';
...
providers: [
...
Base64
]
in Page:
import { Base64 } from '@ionic-native/base64';
constructor(private base64: Base64) { }
let filePath: string = 'file:///...';
this.base64.encodeFile(filePath).then((base64File: string) => {
console.log(base64File);
}, (err) => {
console.log(err);
});
Or use it thins plugins
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With