Я использую ng2-file-upload в проекте Angular 4.x - я пытаюсь передать строку base64, которую можно использовать для передачи этого файла непосредственно в класс FileUploader - я не могу быть уверен, что это даже можно посмотреть документацию в настоящее время?
https://github.com/valor-software/ng2-file-upload
public onPhotoEditBase64(base64, position): void {
let file = this.dataURLtoFile(base64, 'cchq-export');
console.log('fileObj', file); // outputs File object in console
// unsure how to pass the `file` variable into the ng2-fileupload in the existing array to replace the existing image based on the `position` parameter
}
/**
* convert image base64 uri to file object
* @param string dataurl
* @param string filename
* @returns {File}
*/
public dataURLtoFile(dataurl, filename) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
// fix for Internet Explorer
if (window.navigator && window.navigator.msSaveOrOpenBlob) { // IE workaround
let blob = <any>{};
blob = new Blob([u8arr], { type:mime });
blob.lastModifiedDate = new Date();
blob.name = filename;
return blob;
} else {
return new File([u8arr], filename, {type:mime});
}
}