Django Rest_Framework File upload using Ajax - django

I'm beginner of django rest_framework.
I want to implement file upload feature to my project,
and I did some search, but I could not get any helpful example.
So, is there somebody who can tell me some reference or example in rest framework file upload?

Uploading a file using Django Rest Framework can be done independently from the method that you are using to send the request (Ajax in this case).
You can follow this to have more information about how it is done

Related

How to Create an api to upload xml file in django

I need to create an API in Django that will use to take an XML file.
Main Question:
I have created models and serialization and but files that have not to save in Django after extracting the data file will be deleted. now I can not understand the view part(api) please help.
If you wish to upload a file using DRF, you might want to take a look at this topic. It should give you an idea of what to do

Deploy both .html embedded form and .bpmn model using rest API

according this article its possible to deploy both bpmn model and its embedded form with camunda API requests. the problem is that I dont want to use curl tools. I need to deploy both .bpmn model and .html form files with statndard camunda API post method .
I’ve ever do this to deploy my .bpmn model with generated forms type. but righ now I want to deploy embedded forms (as a seperate .html file). now, how can i upload both of these files with rest API?
( I know that i should use ‘embedded:deployment:sampleEmbeddedForm.html’ in modeler form key)
In addition, I use postman to test these rest APIs.
I would be very grateful if you could help me.
according to help of a friend that the answer is posted here, its possible by adding a new body parameter, as name as form name.

Integrating django-import-export with react

I have a postgresql database and I want to add data to it.
I want to upload an excel file containing the data and save it to database.
I have a backend server of django and a frontend server of React.
I am easily able to import the data from the excel sheet to database using django_import_export but from the django admin.
What I want is, to do this using React and for normal users(non superusers) also. Is there a way to integrate django_import_export with react? Any other way to implement this functionality is also apreciated.
Presumably your backend uses a REST API to handle requests from the frontend. So, you can write an API handler which receives the Excel data posted to it.
The Django API handler can create an import process to handle upload. Check the documentation for more information.
Note that if you are loading large files, then you might want to handle the upload asychronously. This is little more tricky, but you could look at Celery to help with this.

use django-rest-swagger 2 with custom swagger.json

I have a project build with django-rest-framework, and I want to use django-rest-swagger to get API documentation, so I made a swagger.json file via swagger editor, then my question is:
How can I make django-rest-swagger read and render my own swagger.json instead of auto-generated from code?
I've checked the django-rest-swagger doc over and over again but nothing found about that.
Any comment will be appreciated.
I know this is old post, but I ran into the same issue and wanted to provide my work around.
If you are trying to create a Swagger UI from an external JSON, this was my work around. I am using django but wanted to provide the swagger api of another framework and server. Here are two options:
The simplest solution is to just manually render the swagger html template and insert the endpoint url that provides the JSON inside SwaggerUi(), this is generally located in the last block.
Alternatively, if you cannot access the json directly or have a static file, create your own rest end point that either reads the file, or makes the request to the remote server, and then itself serves up the desired JSON. Reference this endpoint in your swagger template.

Can we create a Rest API view using DRF to download a file from server?

I am trying to create a Rest API which downloads files from server. Can we do it using Django Rest Framework? Is this a valid case?
If yes a sample view snippet would be more helpful
Yes you can, DRF allows you to return any kind of response in its views, so you can return a file just like you would do in a regular Django view.
There's no requirement for you to use the Response class, you can also return regular HttpResponse or StreamingHttpResponse objects from your views if required. DRF API guide section