Im creating an app for uploading pictures to a wordpress site. I am using Ionic with capacitor to create the app for Ios and Android. Everything works great on Android. But i have an issue on Ios.
When i take the base64 data from the Camera plugin and try to convert it to a Blob with the Blob() constructor it returns an empty array as seen in the screenshot from a console.log.
The function that returns the blob is here (Inspired by this post):
const b64toBlob = (b64Data: string, contentType = 'image/jpeg', sliceSize = 512) => {
const byteCharacters = atob(b64Data)
const byteArrays = []
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize)
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)
}
console.log('bytearrays',byteArrays)
const blob = new Blob(byteArrays, { type: contentType })
console.log('Blob:')
console.log(blob)
return blob
}
export default b64toBlob
I have tried searching for other similar problems but couldn't find any with the same issue.