简体   繁体   中英

How can I send an image in base64 with ng2-file-upload?

The title is my question, how I can send an image in base64 with ng2-file-upload ?

My code in Angular 4 :

public uploader: FileUploader = new FileUploader({
   url: URL,
   allowedMimeType: ['application/pdf', 'image/jpeg', 'image/png'],
   maxFileSize: 10 * 1024 * 1024, // 10 MB
   queueLimit: 3,
   disableMultipart: true,
});

I solved this way:

saveImages() {
    let fileCount: number = this.uploader.queue.length;
    if (fileCount > 0) {
    this.uploader.queue.forEach((val, i, array) => {
        let fileReader = new FileReader();
        fileReader.onloadend = (e) => {
            let imageData = fileReader.result;
            let rawData = imageData.split("base64,");
            if (rawData.length > 1) {
                rawData = rawData[1];
            }
        }
        fileReader.readAsDataURL(val._file);
    });
}

took from here: https://github.com/valor-software/ng2-file-upload/issues/949

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM