我正在使用ng2-file-upload將文件上傳到我的angular2應用程序。問題是,當我點擊'上傳'按鈕時,我得到一個404(未找到)錯誤,這意味着我沒有找到我爲上傳設置的目錄。 這裏是我的組件:使用ng2-file-upload上傳文件時出現404(Not Found)錯誤
import { Component } from '@angular/core';
import { FileUploader } from 'ng2-file-upload';
const URL = 'http://localhost:4200/src/app/uploads/';
@Component({
selector: 'upload-file',
templateUrl: 'upload-file.html'
})
export class UploadCvComponent {
uploader: FileUploader = new FileUploader({ url: URL });
hasBaseDropZoneOver: boolean = false;
hasAnotherDropZoneOver: boolean = false;
fileOverBase(e: any): void {
this.hasBaseDropZoneOver = e;
}
fileOverAnother(e: any): void {
this.hasAnotherDropZoneOver = e;
}
}
我創建了一個目錄用於保存上傳文件在/ src目錄/程序/上傳/。還有什麼我需要做的工作,或FileUploader應該做的工作的其餘部分? 我相信我得到的錯誤是因爲我正在使用Angular2應用程序的路由器,並且該URL(http://localhost:4200/src/app/uploads/)未在路由器中定義。
有人能請指教嗎? 非常感謝!
謝謝,但我不知道你的意思。我使用這個模塊: https://github.com/valor-software/ng2-file-upload 和我的應用程序運行在http:// localhost:4200 我不知道你的意思是「文件-catcher.js示例「。 – decebal
我更新了答案。看看是否可以幫助你。 – Flinkas
我會看看這個。很高興知道我遇到的問題與後端有關。我以爲我在Angular做錯了什麼。非常感謝! – decebal