0

I want to upload, process and discard a JSON file without saving it in a database.

views.py

parser_classes(['FileUploadParser'])
@api_view(['POST'])
def upload_file(request):
    file = request.FILES.get('file')
    # process the file
    return JsonResponse('status':'successful')

urls.py

urlpatterns = [
    path('api/upload_file/', views.upload_file),
]

I am setting the header as Content-Type: multipart/form-data

Then it is showing the error "Multipart form parse error - Invalid boundary in multipart: None"

What is the correct way of uploading a JSON file in DRF ?

Python version : 3.6.9
Django version : 3.2.3

jadhavvv
  • 3
  • 1
  • 2
  • Does this answer your question? [How to manipulate user uploaded files in django without saving it?](https://stackoverflow.com/questions/37975156/how-to-manipulate-user-uploaded-files-in-django-without-saving-it) – Faboor May 19 '21 at 13:24
  • @Faboor This does not answer my question as my question is specific to JSON files. – jadhavvv May 20 '21 at 06:02

1 Answers1

0

I found the answer after trial and error. Basically the header part should be application/json in case of a JSON file upload. The data of the file can be accessed through request.data.
The request.FILES would be empty in case of a JSON file.

jadhavvv
  • 3
  • 1
  • 2