0
votes

im looking for a way to convert PDF File to base64 string .

i have tried with the ionic base64 plugin which works on Android but not for IOS.

i have also tried the below file plugin

this.file.readAsDataURL(“filepath”, fileName).then(

                      file64 => {
                        console.log('file in 64: ', file64);
                        the file64 returns this value  == data:application/pdf;base64" and nothing else
                      
                      }).catch(err => {
                      console.log('booooooo');
                    });

filepath looks like this == “file:///Users/venkatswamydandaboina/Library/Developer/CoreSimulator/Devices/9A8C76B7-F443-409E-8B62-377E7713DB67/data/Containers/Data/Application/D1AD60AE-D75C-4065-8B44-32470A3DA5DA/Library/NoCloud/”

but it doesnt returns base64 string it only returns “data:application/pdf;base64”.

Please help me out. Thanks

1

1 Answers

0
votes

data:application/pdf;base64 is the standard metadata that gets appending to the base64 format to indicate the type of the file.

Instead of checking this == xyz, You can do file.includes('data:application/pdf;base64')