django REST framework nested serializer and POST nested JSON with files django REST framework nested serializer and POST nested JSON with files vue.js vue.js

django REST framework nested serializer and POST nested JSON with files


According DRF documentation,

Most parsers, such as e.g. JSON don't support file uploads. Django's regular FILE_UPLOAD_HANDLERS are used for handling uploaded files.

One option is to use Javascript FormData API to send multipart data (works with VueJS/AngularJS)

var fd = new FormData();fd.append('title', 'Anne of Green Gables')fd.append('author_name', 'Lucy Maud Montgomery')fd.append('author_profilepicture_set', files[])$http.post('url', fd, {   headers: {       'Content-Type': 'multipart/form-data'   }});