<p>首先,您应该将文件发布到<code>/upload/</code>端点,您的主体必须是<code>form-data</code>,例如,在postman中具有以下值:</p>
<pre><code>KEY : files
VALUE : "The file you want to save"
</code></pre>
<p>小心,<code>KEY</code>值必须始终为<code>files</code>,然后响应将如下所示:</p>
<pre><code>[
{
"_id": "5f38db271f720e3348b75327",
"name": "testImage",
"alternativeText": null,
"caption": null,
"hash": "testImage_d12913636e",
"ext": ".jpeg",
"mime": "image/jpeg",
"size": 18.4,
"width": 512,
"height": 213,
"url": "/uploads/testImage_d12913636e.jpeg",
"formats": {
"thumbnail": {
"hash": "thumbnail_testImage_d12913636e",
"ext": ".jpeg",
"mime": "image/jpeg",
"width": 245,
"height": 102,
"size": 5.03,
"path": null,
"url": "/uploads/thumbnail_testImage_d12913636e.jpeg"
},
"small": {
"hash": "small_testImage_d12913636e",
"ext": ".jpeg",
"mime": "image/jpeg",
"width": 500,
"height": 208,
"size": 17.03,
"path": null,
"url": "/uploads/small_testImage_d12913636e.jpeg"
}
},
"provider": "local",
"related": [],
"createdAt": "2020-08-16T07:07:19.355Z",
"updatedAt": "2020-08-16T07:07:19.355Z",
"__v": 0,
"id": "5f38db271f720e3348b75327"
}
]
</code></pre>
<p>然后,每当您想要将图像或文件设置为字段时,只需使用上述响应的<code>id</code></p>