如何使用 ng2-file-upload 在 base64 中发送图像?
How can I send an image in base64 with 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
标题是我的问题,如何使用 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