I want to download images in my project which should store in the device, so I have used FIlesystem in that. here I am getting the image data from the server (in the form of URL ), I have converted this image Url to base64Data but I am getting an error of “Filesystem plugin is not implemented on android.”
Error: “Filesystem” plugin is not implemented on android
below I am providing my code:
downloadFile(){
this.saveToMobileStorage(this.base64Data, ‘yourFileName.jpg’);
}
async saveToMobileStorage(base64Data: string, fileName: string) {
try {
const blobData = this.base64toBlob(base64Data);
const base64String = URL.createObjectURL(blobData);
const dataDirectory = Directory.Data;
const fileWriteOptions:any = {
path: fileName,
data: base64String,
directory: dataDirectory,
};
await Filesystem.writeFile(fileWriteOptions);
console.log('File saved successfully.');
} catch (error) {
console.error(‘Failed to save the file:’, error);
}
}
base64toBlob(base64Data: string): Blob {
const byteCharacters = atob(base64Data);
const byteArrays = ;
for (let offset = 0; offset < byteCharacters.length; offset += 512) {
const slice = byteCharacters.slice(offset, offset + 512);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
return new Blob(byteArrays, { type: ‘image/jpeg’ }); // Adjust the MIME type according to your data.
}
can anyone please help me out of this
Thanks