hi I can anyone help me I need to get just the base_64 code of the csv file I want to upload
this is my code with filter of csv
function readCSV(input) {
if (input.files && input.files[0]) {
var filename = input.files[0].name;
var ext = filename.split('.').pop();
if(input.files[0].type == "text/csv" || ext == "csv" || ext == "xls"){
var reader = new FileReader();
reader.onload = function (e) {
var base_64 = e.target.result;
console.log(base_64);
var array = new Uint8Array(100);
array[42] = 10;
$('#file_name').html(input.files[0].name);
$('#filename').val(input.files[0].name);
$('#content').val(base_64);
}
reader.readAsDataURL(input.files[0]);
}else{
$('#file_name').html('<span style="color:red; font-size:11px"><i class="fa fa-ban"></i> Invalid File Please try again!</span>');
}
}
}
in my logcat when I console.log(base_64)
the result from Google Chrome was
data:base64,UHJvZHVjdCBOYW1lL....(rest of base_64 string)
I just need to have the base_64 string
so I came out with this solution
//replace function
content.replace('data:;base64,', '');
i just remove the data:base64, in the string
but when i tried in firefox the result was
data:application/octet-stream;base64,UHJvZHVjdCBOYW1lL....(rest of base_64 string)
differ from the first result so my replace function won't work
but I don't want to add another replace function because my worries is if browser push an update maybe the data:base64 will be 1.0.data:base64 or v.1.data:base64 so whenever the string changes my system will fail.
could anyone help me please. I just need to get the base_64 string, Thanks in advance.