我有一种必须通过 Curl 的 http.post 类型,请输入以下示例:
curl -X POST -F 'files=@/path/to/pictures/avatar.jpg&refId=5a993616b8e66660e8baf45c&ref=user&source=users-permissions&field=avatar' http://localhost:1337/upload
如您所见,将图像发送到特定字段。此卷曲由此 JSON 表示:
{
"files": "...", // Buffer or stream of file(s)
"path": "user/avatar", // Uploading folder of file(s).
"refId": "5a993616b8e66660e8baf45c", // User's Id.
"ref": "user", // Model name.
"source": "users-permissions", // Plugin name.
"field": "avatar" // Field name in the User model.
}
喜欢这个文档:https ://strapi.io/documentation/3.xx/guides/upload.html#examples
好吧,在 Angular 中这样做:
在我的组件的 html 中创建一个输入:
<input type="file" name="file" (change)="onFileSelected($event)">
创建您的活动:
onFileSelected(event) {
console.log(event);
}
我在其中的文件中有几个结果:
files: FileList
0: File(58456)
lastModified: 1542844204930
lastModifiedDate: Wed Nov 21 2018 21:50:04 GMT-0200 (Horário de Verão de Brasília) {}
name: "8.jpg"
size: 58456
type: "image/jpeg"
webkitRelativePath: ""
好的,但是使用 Postman 进行任何测试以更好地了解我可以执行此操作的人,返回“true”,但我的数据库中没有任何反应:
由于我已经拥有了我需要的所有数据,我如何使用开头显示的 curl 和 post-Angled 方法,甚至 Postman(这会有更清晰的想法)?