擅长:python、mysql、java
<p><em>终于做到了</em></p>
<p>要点是,您必须首先将图像/文件上载到<code>/upload</code>。然后,要将媒体添加到集合类型条目中,请在媒体字段中,引用刚才上载内容的<code>id</code></p>
<p>像这样上传媒体:</p>
<pre class="lang-py prettyprint-override"><code>import requests
import json
files = {'files': ('Screenshot_5.png', open('test.jpeg', 'rb'), 'image', {'uri': ''})}
response = requests.post('http://localhost:1337/upload', files=files)
print(response.status_code)
# `response.text` holds the id of what you just uploaded
</code></pre>
<p>您的媒体现在应该在Strapi媒体库中(您应该仔细检查)</p>
<p>最后,现在您可以创建一个条目(正如您通常所做的那样)并使用您上传到添加媒体的内容的<code>id</code></p>
<pre class="lang-py prettyprint-override"><code>payload = {
"Type": 'info',
"Message": 'lorem ipsum beep bop',
"Screenshot": 1, # this is the id of the media you uploaded
}
response = requests.post('http://localhost:1337/logs', json=payload)
print(response.status_code)
</code></pre>