我在文件‘../src/app/assets/’中上传图像时遇到问题。我有以下表单
<form [formGroup]="formRegister" novalidate="">
<div class="form-group">
<label for="exampleInputImage">Image</label>
<input type="file" (change)="onFileSelect($event)" name="image"
class="form-control" placeholder="Enter votre image">
</div>
</form>
<button type="button" (click)="onRegister()">Submit</button>在我的ts中
formRegister: FormGroup;
errorMail: string = "";
selectedFile: File = null;
constructor(private appService: AppServiceService, private http: HttpClient) { }
ngOnInit() {
this.formRegister = new FormGroup({
image: new FormControl('', [Validators.required])
});
}
onFileSelect(event) {
console.log("event : ", event);
this.selectedFile = <File>event.target.files[0];
}
onRegister(): void {
const fd = new FormData();
fd.append('image', this.selectedFile);
const req = new HttpRequest('POST', '../src/app/assets/', fd);
this.http.request(req).subscribe(events => {
console.log("Upload Image", events);
},
(err: HttpErrorResponse) => {
console.log("Erreur : ", err.message); // Show error, if any.
});
}在我的控制台中,我有一个错误:http://localhost:4200/src/app/assets/ 404 (未找到)
我的代码中的问题出在哪里,谢谢。
发布于 2019-10-22 00:32:29
这是不可能应用的图像在文件夹中只有角度。可以将图像转换为base64格式并注册为string格式。
当你想要应用文件夹中的镜像时,有必要使用服务器(Node Js,spring boot ...)
还有谢谢
https://stackoverflow.com/questions/58486065
复制相似问题