如何使用ng2-file-upload在base64中发送图像?

时间:2018-01-16 10:30:47

标签: angular base64 ng2-file-upload

标题是我的问题,我如何使用ng2-file-upload在base64中发送图像?

我的代码在 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,
});

1 个答案:

答案 0 :(得分:3)

我这样解决了:

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);
    });
}

从这里开始: https://github.com/valor-software/ng2-file-upload/issues/949