简体   繁体   English

如何通过REST API上传

[英]How to upload via REST API

I have an angular 5 app and I'm using the primeng upload tool. 我有一个Angle 5应用,正在使用primeng上传工具。 the api post for uploading requires three parameters: file (file), id (string), fileType (string). 用于上传的api帖子需要三个参数:file(文件),id(字符串),fileType(字符串)。 I can do the latter two but the file type i just don't understand. 我可以做到后两个,但我只是不了解文件类型。 the latter two are strings, got it, but how do i address the file part? 后两个是字符串,知道了,但是我该如何解决文件部分呢?

this is my json post: 这是我的json帖子:

[{ "file" : <<DATA>>, "id": "1234123", "fileType": "doc" }]

What and how to I put in something for the file type? 如何为文件类型添加内容?

PrimeNG FileUpload's documentation is quite good so I'd suggest taking a closer look at the documentation at: PrimeNG File Upload PrimeNG FileUpload的文档非常不错,因此建议您仔细阅读以下文档: PrimeNG File Upload

For your specific requirement, I'd suggest taking PrimeNG File Upload and make it as "fancy file picker". 根据您的特定要求,建议您将PrimeNG File Upload用作“ fancy file picker”。 Snippets as below: 片段如下:

HTML
<p-fileUpload 
  name="demo[]" 
  auto="true"
  customUpload="true" 
  (uploadHandler)="myUploader($event)" 
  multiple="multiple">
</p-fileUpload>

TS
myUploader(event) {
 consol.log(event.files) //This will return all of the files that are selected. You can omit multiple files by getting rid of `multiple` attribute from the template
//Take this event.files and do whatever you want with it
}

Plunker example, turn on the Console 以Plunker为例,打开控制台 控制台中的文件对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM