【问题标题】:How can I send an image in base64 with ng2-file-upload?如何使用 ng2-file-upload 以 base64 格式发送图像?
【发布时间】:2018-01-16 10:30:47
【问题描述】:

标题是我的问题,如何使用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,
});

【问题讨论】:

    标签: angular base64 ng2-file-upload


    【解决方案1】:

    我是这样解决的:

    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

    【讨论】:

    • 我会测试这个,tnks。
    猜你喜欢
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2019-05-09
    相关资源
    最近更新 更多