api функция отправки файла корректно записывает данные в формдату
This commit is contained in:
parent
b668816818
commit
c1862723ee
@ -33,17 +33,16 @@ console.log(qid)
|
|||||||
|
|
||||||
//body ={file, filename}
|
//body ={file, filename}
|
||||||
export function sendFile({ questionId, body, qid }: any) {
|
export function sendFile({ questionId, body, qid }: any) {
|
||||||
|
console.log(body)
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const fd: any = {
|
const answers: any = [{
|
||||||
question_id: questionId,
|
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("answers", JSON.stringify(answers));
|
||||||
|
formData.append(body.name, body.file);
|
||||||
formData.append("qid", qid);
|
formData.append("qid", qid);
|
||||||
|
|
||||||
return makeRequest<FormData, { [key: string]: string; }>({
|
return makeRequest<FormData, { [key: string]: string; }>({
|
||||||
|
@ -51,13 +51,13 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
const uploadFile = async ({ target }: ChangeEvent<HTMLInputElement>) => {
|
const uploadFile = async ({ target }: ChangeEvent<HTMLInputElement>) => {
|
||||||
const file = target.files?.[0];
|
const file = target.files?.[0];
|
||||||
if (file) {
|
if (file) {
|
||||||
|
console.log(file)
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await sendFile({
|
await sendFile({
|
||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: {
|
body: {
|
||||||
file: `${file.name}|${URL.createObjectURL(file)}`,
|
file: file,
|
||||||
name: file.name
|
name: file.name
|
||||||
},
|
},
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
Loading…
Reference in New Issue
Block a user