title: How to Pass an Image File to a API Endpoint
body: <p>I have a web services with DRF, I have POSTMAN passing the right all fields right with success including the image file ['avatar']
  [<img src="https://i.stack.imgur.com/Pof24.png" alt="ango">]<a href="https://i.stack.imgur.com/Pof24.png" rel="nofollow noreferrer">1</a></p>
  
  <p>Now how do i pass the image file from a Django Form, but i keep getting Error 400, Bad request. Please how do i encode the image file to be passed into the API endpoint .</p>
  
  <p>html</p>
  
  <pre><code>&lt;form method="post" action="#" enctype="multipart/form-data"&gt;
                            {% csrf_token %}
                                &lt;label for="phone"&gt;Enter Phone&lt;/label&gt;
                                {{ form.phone }} &lt;br /&gt;
                                &lt;label for="bvn"&gt;Enter BVN&lt;/label&gt;
                                {{ form.bvn }} &lt;br /&gt;
                                &lt;label for="avatar"&gt;Upload Avatar&lt;/label&gt;
                                {{ form.avatar }} &lt;br /&gt;
                                &lt;button type="submit" class="btn btn-primary" &gt;Submit&lt;/button&gt;
  
                            &lt;/form&gt;
  </code></pre>
  
  <p>views.py </p>
  
  <pre><code>def form_valid(self, form):
      token = self.request.session['session_token']
      headers = {"Content-Type": 'application/json', "Authorization": "Token " + token}
  
      parameters = {
          'bvn': form.cleaned_data['bvn'],
          'phone': form.cleaned_data['phone'],
          'avatar': self.request.FILES['avatar']
      }
      response = requests.put(str(settings.API_END_POINT + '/customer_profile_api/'), data=parameters,
                               headers=headers)
      if response.status_code in settings.SUCCESS_CODES:
          messages.success(self.request, 'Successfully updated profile')
      else:
          messages.error(self.request, 'API Error %s' % response.status_code)
  
      return super(CustomerDashboard, self).form_valid(form)
  </code></pre>
  
  <p>form.py </p>
  
  <pre><code>class ProfileUpdateForm(forms.Form):
      """customer profile update form"""
      phone = forms.CharField(required=False, widget=NumberInput(attrs={'class': 'form-control',
                                                                        'type': 'number', 'id': 'phone',
                                                                        'placeholder': 'Enter Phone Number'}))
      bvn = forms.CharField(required=False, widget=NumberInput(attrs={'class': 'form-control',
                                                                        'type': 'number', 'id': 'bvn',
                                                                        'placeholder': 'Enter BVN'}))
      avatar = forms.ImageField(required=False, widget=ClearableFileInput(attrs={'class': 'form-control',
                                                                        'type': 'file', 'id': 'avatar',
                                                                        'placeholder': 'Upload Avatar'}))
  </code></pre>