Код: Выделить всё
png
Это мой код Fastapi:
Код: Выделить всё
@app.post("/api/")
async def dummy_file_return(metadata=Body(...),file=File(...)):
print("content_type is")
print(file.content_type)
Код: Выделить всё
$curl -X POST -F file=@0_for_django_testcase.png -F metadata='{"meta":"test"}' localhost:8008/api/
content_type is
image/png
Я могу видеть content_type автоматически и Image/png set. Я попробовал то же самое по запросам of python .
Код: Выделить всё
response = requests.post(
url,
data={"metadata":json.dumps({"meta":"test")},
files = {
"file": open('0_for_django_testcase.png','rb')
},
)
< /code>
Консоль показывает < /p>
content_type is < /p>
< /blockquote>
content_type
Почему это различие происходит? Испытание я проверил эти шаблоны с заголовками, но оба возвращают ошибка.
Код: Выделить всё
response = requests.post(
url,
data={"metadata":json.dumps({"meta":"test")},
files = {
"file": open('0_for_django_testcase.png','rb')
},
headers={
"Content-Type":"image/png"
}
)
response = requests.post(
url,
data={"metadata":json.dumps({"meta":"test")},
files = {
"file": open('0_for_django_testcase.png','rb')
},
headers={
"Content-Type":"multipart/form-data"
}
)
Подробнее здесь: https://stackoverflow.com/questions/766 ... url-than-p