Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

csrf failed while uploading the file through swagger

I am trying to upload an image file using swagger it throws

{ "detail": "CSRF Failed: CSRF token missing or incorrect." }

. It is important to mention that i'm using django-rest-swagger version 0.3.0 and django version 1.7.

YAML for uploading a picture looks like:

parameters:
    - name: image
      in: formData
      required: true
      type: file
    - name: caption
      required: true
      type: string

I don't want to use @csrf_exempt. I tried to pass a header into this but that didn't work. header was something like:

    - name: X-CSRF-Token
      description: csrftoken to be passed in header
      in: header
      required: true
      type: string

any help will be appreciated.

like image 498
stillfool Avatar asked Aug 04 '15 14:08

stillfool


1 Answers

I had the same issue, if you're up to date with Django, it's just a misnamed header.

Use 'X-CSRFToken' instead of 'X-CSRF-Token', that worked for me.

like image 173
Christian Brintnall Avatar answered Oct 19 '22 05:10

Christian Brintnall