Код: Выделить всё
var formData = new FormData();
formData.append("data",{"test":1});
//make jpg image from canvas.
var image = ref_canvas_release.current.toDataURL('image/jpeg', 0.85);
//////// confirm and test the image file is correctly created. it created!
var a = document.createElement('a');
a.href = image;
a.download = 'test.jpg';
a.click();
////////
formData.append("file",image);
axios.post("/myuploader",formData,{headers: {'Content-Type': 'application/form-data'}}).then(res=>{
console.log(res)
});
Код: Выделить всё
from fastapi import FastAPI,UploadFile, File,Depends,status,Body,Request
@app.post('/myuploader')
def uploader(request: Request):
print(request.query_params['data'])// key error 'data'
return {"sending":"OK"}
Существует ли общепринятая практика одновременной отправки файла и json с помощью формы -data?
Спасибо @deceze
Я проверяю эти документы.
https://www.starlette.io/requests/
и пытался изменить
Код: Выделить всё
@app.post('/myuploader')
def uploader(request: Request):
print(request.stream())//
return {"sending":"OK"}
Я думаю, что могу сделать шаг вперед, но все еще в замешательстве, как я могу получить данные и файл отсюда или использовать Requst напрямую — не лучшая идея?
Подробнее здесь: https://stackoverflow.com/questions/793 ... by-fastapi
Мобильная версия