angular-httpclient - 发布 csv 上传的文件,通过 body 其名称和内容 Angular
问题描述
我有一个带有 data-import.service、data-import 组件及其子组件的 Data-Import-Module:uploader.component(在上传器模块中定义了自己的服务) save.component(button) 和 display-table.component (按钮)和 table.component。
我想上传 csv 文件(我想它是带有点的表,Point(x;y;)),使用 httpClient.post 方法将其保存到服务器,其中传递 body{fileName, content-of-csv-parsed to-json或者只是一个表格},显示一个包含上传文件内容的表格。
httpClient 方法对我来说是新的,我真的不明白什么是 headers 和 param,它们是 post 方法中的第三个(选项)参数——我应该把 fileName 放在那里还是应该把它的 body 和 Point[] 放在一起?body 可以有多个参数吗?我应该创建 File(fileName:string, points: Point[]) 并将其作为正文吗?
export class DataImportService {
constructor (private http: HttpClient){}
baseUrl: string="api/files";
postFile(fileName:string, points: Point[] ):Observable<any>{
return this.http.post(this.baseUrl,{fileName,points} ){};
}
对比
export class DataImportService {
constructor (private http: HttpClient){}
baseUrl: string="api/files";
postFile(file:File ):Observable<File>{
return this.http.post(this.baseUrl,file ){};
}
这是我的两个概念,我真的很想了解:
DataImportComponent{
constructor(private dataService: DataImportService)
saveFile(data.csv){
...
return this.dataService.dataService.post(...).subscribe(
x=>{parsed to json});
)
}
}
解决方案
推荐阅读
- angularjs - Angularjs:调用 REST API 从服务器获取 docx 文档
- javascript - 使用 Observables (Angular) 在网站上动态添加帖子
- xserver - 增加 XTEST 指针的按钮数量?
- javascript - Accordion - 在 Ajax 调用之后打开第一个条目
- python - Jira 使用 python 创建问题
- nginx - NGINX:从位置阻止,如果捕获参数为空
- c# - 如何将 MS Graph 消息保存为 .eml 文件
- laravel - 在 OAuth 2 和会话身份验证之间共享登录
- elasticsearch - Elasticsearch 6.2.4:如何按 _score 对聚合结果进行排序?
- php - 联系表 - 提交后如何不重定向到另一个页面