<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello,<br>
<br>
<div>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.</div>
<div><br>
</div>
<div>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?</div>
<div><br>
</div>
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.<br>
</div>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
console.log("Trying to upload document ")
<div> //now to send the document upload in geonode</div>
<div> let url = 'http://127.0.0.1:4040/api/v2/documents/'; </div>
<div> var crf_token1 = $('[name="csrfmiddlewaretoken"]').attr('value'); </div>
<div> </div>
<div> //method where we use a token</div>
<div> let headers = new Headers();</div>
<div> var crf_token = $('[name="csrfmiddlewaretoken"]').attr('value');</div>
<div> headers.set('X-CSRFToken', crf_token); </div>
<div><br>
</div>
<div> // lets first get a good sample file </div>
<div> var ds_url = 'http://127.0.0.1:4040/static/ds_assets/dtest.txt'; </div>
<div> var fileD; </div>
<div> fetch(ds_url)</div>
<div> .then( res => res.blob() )</div>
<div> .then( blob => {</div>
<div> fileD = window.URL.createObjectURL(blob);</div>
<div> }); </div>
<div> </div>
<div> var formData = new FormData(); </div>
<div> //fetch related parameters</div>
<div> formData.append('file', fileD); </div>
<div> formData.append('owner', 'admin'); formData.append('title', 'testdoc');</div>
<div> formData.append('abstract', 'testdoc'); formData.append('attribution', 'test');</div>
<div> formData.append('bbox_polygon', 'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)))');</div>
<div> formData.append('constraints_other', 'no'); formData.append('data_quality_statement', 'no');</div>
<div> formData.append('doi', 'test'); formData.append('embed_url', 'test');</div>
<div> formData.append('is_approved', 'true'); formData.append('is_published', 'true');</div>
<div> formData.append('ll_bbox_polygon', 'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)))');</div>
<div> formData.append('maintenance_frequency', '1'); formData.append('metadata_only', 'true');</div>
<div> formData.append('popular_count', '1'); formData.append('share_count', '1');</div>
<div> formData.append('srid', '1'); formData.append('purpose', '1'); formData.append('rating', '1');</div>
<div> formData.append('language', 'English'); formData.append('supplemental_information', 'No information provided');</div>
<div> formData.append('temporal_extent_end', '2022-02-02 12:21'); formData.append('temporal_extent_start', '2022-02-02 12:21');</div>
<div> formData.append('thumbnail_url', 'test'); formData.append('Regions', 'Global');</div>
<div> formData.append('Responsible', 'admin'); formData.append('date', '2022-02-02 12:21');</div>
<div> formData.append('edition', 'test'); formData.append('date_type', 'test');</div>
<div> </div>
<div> fetch(url, {method:'POST',</div>
<div> headers: headers ,</div>
<div> body: formData,</div>
<div> credentials: "same-origin",</div>
<div> })</div>
<div> .then(response => response.json())</div>
.then(json => console.log(json));<br>
<br>
</div>
<div id="Signature">
<div><span style="font-family:Calibri, Arial, Helvetica, sans-serif;text-align:start;background-color:rgb(255, 255, 255);display:inline !important">Dr. Pankaj Sharma<br>
</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; text-align: start; background-color: rgb(255, 255, 255); display: inline !important; color: rgb(12, 100, 192);"><i>Research Fellow</i></span><span style="font-family:Calibri, Arial, Helvetica, sans-serif;text-align:start;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0);">GIScience team, School of Environment</span></div>
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; text-align: start; background-color: rgb(255, 255, 255); display: inline !important; color: rgb(0, 0, 0);">The University of Auckland</span></div>
</div>
</div>
</body>
</html>