0

Is it possible to upload file (Image) to Django rest api from Reactjs client using Formik ?

2 Answers 2

0

Django/DRF allows to upload file quite easly : https://docs.djangoproject.com/fr/2.2/topics/http/file-uploads/ and for DRF : Django Rest Framework File Upload

As for Formik: ReactJS: How to handle Image / File upload with Formik?

Sign up to request clarification or add additional context in comments.

4 Comments

Yes but the problem is that i can't send the file using axios
What do you mean you can't ? You can through almost any known http client. stackoverflow.com/questions/43013858/… for axios e.g. Angular has it's own too.
yes if you look to the response you will find out that is using formData and not formik
Did you check this ? stackoverflow.com/a/56161034/10034177, it uses formik with html element to set the file into the attribute of a native element.
0
const formData = new FormData();
const fileInput = document.querySelector('input[name="profile_picture"]');
if (fileInput && fileInput.files && fileInput.files.length > 0) {
  formData.append('profile_picture', fileInput.files[0]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.