I need to enhance my existing base64 string to image file conversion code by adding metadata such as last modified date, photographer, copyright, and credits. However, the initial attempt below did not yield the desired results. Is there a better way to incorporate this metadata?
In the code snippet provided, the variable `base64Source` represents the dataUri containing the base64 content.
function updateImageMetadata(base64Source, name) {
var base64Content = base64Source.substr(base64Source.indexOf(',') + 1);
var byteString = window.atob(base64Content);
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var file = new Blob([ia], {type: 'image/jpeg'});
return new File([the_file], name);
};
I have attempted modifying the code as shown below:
function updateImageMetadata(base64Source, name) {
var base64Content = base64Source.substr(base64Source.indexOf(',') + 1);
var byteString = window.atob(base64Content);
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var file = new Blob([ia], {type: 'image/jpeg'});
return new File([the_file], name,{
lastModified: new Date().getTime(),
tooltip : 'test tooltip',
caption : 'test caption',
copyright : 'Test',
credits : 'Test'
});
};