Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Which file format django imagefield(filefield) requires?

I use django-rest-framework first time. I use json format by default. I need to send file for creating a new instance. This file has being saved in models.ImageField. However, I don't know which format this field requires for incoming file. I tried to send it in base64, but it isn't suitable.

TestCase for this problem:

class PersonTestCase(APITestCase):
    def setUp(self):
        self.c = APIClient()

    def test_sign_up_with_valid_data(self):
        with open('persons/test/bg.jpg', 'rb') as bg:
            valid_registration_data = {
                ...,
                'background': base64.b64encode(bg.read()).decode('utf-8'),
            }
            response = self.c.post('/persons/sign_up', valid_registration_data)
            self.assertEqual(response.status_code, 201)
            self.assertEqual(Person.objects.count(), 1)
            self.assertEqual(Person.objects.get('username'), 'test_client74562984')

View:

class SignUpView(APIView):
    """
    Create new user
    """
    def post(self, request):
        serializer = UserSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            response = Response(serializer.data, status=status.HTTP_201_CREATED)
            return response
        response = Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
        return response
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!