[GeoNode-users] Implement file upload in GeoNode Django Rest Framework

Pankaj Sharma Pankaj.Sharma at auckland.ac.nz
Thu Mar 24 10:13:17 PDT 2022


I am trying to upload a simple textfile as a Geonode document to Geonode via the Django Rest Framework. I know the file upload using GeoNode DRF is not implemented. I also know that the Geonode DRF is based on the DRF on the Github respository.

I want to implement the file upload facility in Geonode DRF. I have been going in circles looking at the Python code - I know I would have to modify the request.py file, but how?

Anyone can give me some pointers as to where to start, or maybe some file I can replace in DRF and it would start to work. I am posting my FETCH CODE which is not working because the file handler code is not implemented.

 console.log("Trying to upload document ")
     //now to send the document upload in geonode
    let url = '';
    var crf_token1 = $('[name="csrfmiddlewaretoken"]').attr('value');

     //method where we use a token
     let headers = new Headers();
     var crf_token = $('[name="csrfmiddlewaretoken"]').attr('value');
     headers.set('X-CSRFToken', crf_token);

    // lets first get a good sample file
    var ds_url = '';
    var fileD;
      .then( res => res.blob() )
      .then( blob => {
         fileD = window.URL.createObjectURL(blob);

    var formData = new FormData();
    //fetch related parameters
    formData.append('file', fileD);
    formData.append('owner', 'admin');             formData.append('title', 'testdoc');
    formData.append('abstract', 'testdoc');        formData.append('attribution', 'test');
    formData.append('bbox_polygon', 'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)))');
    formData.append('constraints_other', 'no');    formData.append('data_quality_statement', 'no');
    formData.append('doi', 'test');                formData.append('embed_url', 'test');
    formData.append('is_approved', 'true');        formData.append('is_published', 'true');
    formData.append('ll_bbox_polygon', 'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)))');
    formData.append('maintenance_frequency', '1'); formData.append('metadata_only', 'true');
    formData.append('popular_count', '1');         formData.append('share_count', '1');
    formData.append('srid', '1');                  formData.append('purpose', '1');         formData.append('rating', '1');
    formData.append('language', 'English');        formData.append('supplemental_information', 'No information provided');
    formData.append('temporal_extent_end', '2022-02-02 12:21');         formData.append('temporal_extent_start', '2022-02-02 12:21');
    formData.append('thumbnail_url', 'test');      formData.append('Regions', 'Global');
    formData.append('Responsible', 'admin');       formData.append('date', '2022-02-02 12:21');
    formData.append('edition', 'test');            formData.append('date_type', 'test');

    fetch(url, {method:'POST',
            headers: headers ,
            body: formData,
            credentials: "same-origin",
    .then(response => response.json())
    .then(json => console.log(json));

Dr. Pankaj Sharma
Research Fellow
GIScience team, School of Environment
The University of Auckland
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20220324/2c95c6a3/attachment.html>

More information about the geonode-users mailing list