作者,你好,在开发客户端的时候调用方法 'multipartUpload'时报错,报错信息如下:
ERROR Error: Uncaught (in promise): Error: _getFileSize requires Buffer/File/String.
Error: _getFileSize requires Buffer/File/String.
请问,怎么会事儿?如何解决?thank you!
附,其他信息:
1、使用的是angular4框架,组件化开发;
2、语言:typescript;
3、此组件所有代码如下:
`import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
declare const OSS: any;
@component({
selector: 'app-file-upload-oss',
templateUrl: './file-upload-oss.component.html',
styleUrls: ['./file-upload-oss.component.scss']
})
export class FileUploadOssComponent implements OnInit {
// configuration parameter
@input() type?: String = 'rectangle';
@input() region: string;
@input() accessKeyId: string;
@input() accesskey: string;
@input()
set bucket(val: string) {
if (val !== '' && val.indexOf('/') !== val.length - 1) {
val = val + '/';
}
this._bucket = val;
};
get bucket(): string {
return this._bucket;
};
@output() uploadStatus = new EventEmitter();
_bucket: string;
filesList: any[] = [];
// Handle files
handleFiles(files: any[]) {
return new Promise((resolve) => {
for (const file of files) {
file['loading'] = false;
file['remove'] = false;
file['percent'] = 0;
};
resolve(files);
});
};
// click select files
clickSelectFiles($event: any) {
this.filesList.length = 0;
this.handleFiles($event.target.files).then((files: any[]) => {
this.filesList.push(...files);
});
};
// dragover preventDefault
dragover($event: any) {
$event.preventDefault();
};
// drop select files
dropSelectFiles($event: any) {
$event.preventDefault();
this.handleFiles($event.dataTransfer.files).then((files: any[]) => {
this.filesList.push(...files);
});
};
// remove files
removeFile(index: number) {
this.filesList[index]['removeAnimation'] = 'fadeOutRight';
setTimeout(() => {
this.filesList.splice(index, 1);
}, 300);
};
// upload files
uploadFile() {
const file = document.getElementById('btn')['files'][0];
const files = this.filesList;
const key = 'object';
const client = new OSS.Wrapper({
region: this.region,
accessKeyId: this.accessKeyId,
accessKeySecret: this.accesskey,
bucket: this.bucket
});
client.multipartUpload(key, file, {
progress: this.progress
}).then(((res: any) => {
alert(`${res}`);
console.log('upload success');
this.uploadStatus.emit(res);
}));
};
// upload progress
progress(p: any) {
console.log(进度${p}
);
};
constructor() { }
ngOnInit() {
}
}
`