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

标签 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,
});

最佳答案

我是这样解决的:

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

关于angular - 如何使用 ng2-file-upload 在 base64 中发送图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48279138/

相关文章:

angular - 错误 : Metadata version mismatch for module . ../node_modules/@ngx-translate/core/core.d.ts,找到版本 4,预期为 3

typescript - 无法导入自定义组件 - Angular2 和 TypeScript

javascript - AngularJS : Upload base64 image to server

fonts - 将 Base64 字体转换回 ttf 或 otf

Swift 2 解码 base64 总是返回 nil

angular - 如何使用 ng2-file-upload 重置并允许上传文件

javascript - Angular 2 - 链接 Web 服务调用

javascript - 使用 ng2-file-upload 进行 Angular2+ 文件上传 - 子组件不断调用父组件函数

angular - 有没有一种简单的方法来覆盖基本指令?