api функция отправки файла корректно записывает данные в формдату

This commit is contained in:
Nastya 2024-01-22 05:26:39 +03:00
parent b668816818
commit c1862723ee
2 changed files with 7 additions and 8 deletions

@ -33,17 +33,16 @@ console.log(qid)
//body ={file, filename}
export function sendFile({ questionId, body, qid }: any) {
console.log(body)
const formData = new FormData();
const fd: any = {
const answers: any = [{
question_id: questionId,
content: body.name,
}
content: "file:" + body.name,
}]
fd[body.name] = body.file //target.files[0]
const answers = [fd]
formData.append("answers", JSON.stringify(answers));
formData.append(body.name, body.file);
formData.append("qid", qid);
return makeRequest<FormData, { [key: string]: string; }>({

@ -51,13 +51,13 @@ export const File = ({ currentQuestion }: FileProps) => {
const uploadFile = async ({ target }: ChangeEvent<HTMLInputElement>) => {
const file = target.files?.[0];
if (file) {
console.log(file)
try {
await sendFile({
questionId: currentQuestion.id,
body: {
file: `${file.name}|${URL.createObjectURL(file)}`,
file: file,
name: file.name
},
//@ts-ignore