【发布时间】:2021-08-03 01:36:41
【问题描述】:
客户响亮的图像,我根据将图像复制到我的文件夹将图像发送到我的服务器,当返回响应时页面刷新我想防止这种情况-
角度
html
<button mat-button class="load" (click)="onClick()">
<mat-label>התאמה על פי תמונה</mat-label>
<mat-icon>file_upload</mat-icon>
</button>
<input type="file" #fileUpload id="fileUpload"
name="fileUpload" multiple="multiple" accept="image/*"
style="display:none;"
(change)="handleFileInput($event.target.files)" [(ngModel)]="image"
/>
<img *ngIf="availbule" [src]="imgURL" style="width:
250px;height:
150px;" />
组件.ts
从文件资源管理器发送图像以将她复制到我的文件夹
uploadFile(file) {
var arr = this.fileToUpLoud.name.split('/');
let ima = arr[arr.length - 1];
var end=ima.split('.');
const formData = new FormData();
this.namera=Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000;
this.propertySearch.img=(this.namera).toString()+
formatDate(new Date(), 'yyyy-MM-dd', 'en')+'.'+(end[end.length-1]).toString();
formData.append('file', file.data,this.propertySearch.img);
file.inProgress = true;
this._modelService.uploadimageSearch(formData)
.subscribe(data => {
if(data==true){
alert("true")}
else{
alert("false");
}
});
}
服务
public uploadimageSearch(file: FormData): Observable<boolean> {
return this.httpClient.post<boolean>("/api/Model/addNewcustomerImage", file);
}
c#网核
此函数获取图像并将她复制到某个位置
public async Task<bool> addNewcustomerImage(IFormFile file)
{
try
{
string end = file.FileName;
string imgPath = @"C:/Users/AVITAL/Desktop/my-first-project/src/assets/image/";
string finalPath = imgPath + end;
using (var stream = new FileStream(finalPath, FileMode.Create))
{7
await file.CopyToAsync(stream);
stream.Close();
}
}
catch (Exception ex)
{
return false;
}
return true;
}
【问题讨论】:
-
不清楚您遇到了什么问题。
-
这是表格吗?
-
是的,客户需要响亮的图像,我想将她复制到我的文件夹,但是当服务器返回响应时页面响亮
-
请出示表格代码
-
我没有看到表单,只有一个按钮,这是
form还是只是一个按钮?
标签: c# angular asp.net-core