Skip to main content

This is a snippet for the code that I want to do Blob to Base64 string:

This commented part works and that when the URL generated by this is set to img src it displays the image:

var blob = items[i].getAsFile();
//var URLObj = window.URL || window.webkitURL;
//var source = URLObj.createObjectURL(blob);
//console.log("image source=" + source);
                        
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result)
}; // data url!
var source = reader.readAsBinaryString(blob);

The problem is with the the lower code, the source variable generated is null

Update:

Is there an easier way to do this with JQuery to be able to create Base64 String from the Blob file as in the code above?

This is a snippet for the code that I want to do Blob to Base64 string:

This commented part works and that when the URL generated by this is set to img src it displays the image:

var blob = items[i].getAsFile();
//var URLObj = window.URL || window.webkitURL;
//var source = URLObj.createObjectURL(blob);
//console.log("image source=" + source);
                        
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result)
}; // data url!
var source = reader.readAsBinaryString(blob);

The problem is with the the lower code, the source variable generated is null

Update:

Is there an easier way to do this with JQuery to be able to create Base64 String from Blob file as in the code above?

This is a snippet for the code that I want to do Blob to Base64 string:

This commented part works and when the URL generated by this is set to img src it displays the image:

var blob = items[i].getAsFile();
//var URLObj = window.URL || window.webkitURL;
//var source = URLObj.createObjectURL(blob);
//console.log("image source=" + source);
                        
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result)
}; // data url!
var source = reader.readAsBinaryString(blob);

The problem is with the lower code, the source variable generated is null

Update:

Is there an easier way to do this with JQuery to be able to create Base64 String from the Blob file as in the code above?

added 137 characters in body
Source Link
quarks
  • 34.7k
  • 81
  • 302
  • 534

This is a snippet for the code that I want to do Blob to Base64 string:

This commented part works and that when the URL generated by this is set to img src it displays the image:

var blob = items[i].getAsFile();
//var URLObj = window.URL || window.webkitURL;
//var source = URLObj.createObjectURL(blob);
//console.log("image source=" + source);
                        
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result)
}; // data url!
var source = reader.readAsBinaryString(blob);

The problem is with the the lower code, the source variable generated is null

Update:

Is there an easier way to do this with JQuery to be able to create Base64 String from Blob file as in the code above?

This is a snippet for the code that I want to do Blob to Base64 string:

This commented part works and that when the URL generated by this is set to img src it displays the image:

var blob = items[i].getAsFile();
//var URLObj = window.URL || window.webkitURL;
//var source = URLObj.createObjectURL(blob);
//console.log("image source=" + source);
                        
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result)
}; // data url!
var source = reader.readAsBinaryString(blob);

The problem is with the the lower code, the source variable generated is null

This is a snippet for the code that I want to do Blob to Base64 string:

This commented part works and that when the URL generated by this is set to img src it displays the image:

var blob = items[i].getAsFile();
//var URLObj = window.URL || window.webkitURL;
//var source = URLObj.createObjectURL(blob);
//console.log("image source=" + source);
                        
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result)
}; // data url!
var source = reader.readAsBinaryString(blob);

The problem is with the the lower code, the source variable generated is null

Update:

Is there an easier way to do this with JQuery to be able to create Base64 String from Blob file as in the code above?

Source Link
quarks
  • 34.7k
  • 81
  • 302
  • 534

Convert blob to base64

This is a snippet for the code that I want to do Blob to Base64 string:

This commented part works and that when the URL generated by this is set to img src it displays the image:

var blob = items[i].getAsFile();
//var URLObj = window.URL || window.webkitURL;
//var source = URLObj.createObjectURL(blob);
//console.log("image source=" + source);
                        
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result)
}; // data url!
var source = reader.readAsBinaryString(blob);

The problem is with the the lower code, the source variable generated is null