[英]ng2-file-upload and reading file contents
全部,
我正在嘗試讀取使用 ng2-file-upload 拖放的文件的內容,但無法弄清楚。 我希望能夠在上傳之前獲取數據並將其放入網格中。
這是我的 HTML 代碼
<div ng2FileDrop
[ngClass]="{'file-over': hasFileOver}"
(fileOver)="fileOver($event)"
(onFileDrop)="fileDrop($event)"
[uploader]="uploader"
class="well my-drop-zone">
Drop zone
</div>
這是我的 .ts 代碼
public fileDrop(e: any):void {
console.log("drop", e);
this.hasFileOver = e;
}
public fileOver(e: any):void {
console.log("over", e);
console.log(this.uploader);
this.hasFileOver = e;
}
我一直在嘗試很多不同的東西,但無法弄清楚如何獲取數據。
謝謝你
你可以參考這個stackoverflow答案: https : //stackoverflow.com/a/39644736/4337932
這是它所說的:
uploader: FileUploader = new FileUploader({}); //Empty options to avoid having a target URL
reader: FileReader = new FileReader();
ngOnInit() {
this.reader.onload = (ev: any) => {
console.log(ev.target.result);
};
this.uploader.onAfterAddingFile = (fileItem: any) => {
this.reader.readAsText(fileItem._file);
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.