0

I am trying to use JavaScript (not Nodejs) to upload/insert a GeoNode document from memory. I have tried the JavaScript fetch API from browser. The GET works, but the POST gives error.

Someone advised to add these required fields. Anyone know how to prevent the required fields error or add them as part of the fetch?

let url = 'https://DOMAIN/api/v2/documents/';
let username = 'admin';
let password = 'PWD';        
let headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa(username + ":" + password));        
var crf_token = $('[name="csrfmiddlewaretoken"]').attr('value');
headers.set('X-CSRFToken', crf_token);
const formData = new FormData()
formData.append('newDocumentName', file)
headers.set('body',formData) 
fetch(url, {method:'POST',
        headers: headers
 })
.then(response => response.json())
.then(json => console.log(json));


ERROR MESSAGE IN CONSOLE:
POST https://DOMAIN/api/v2/documents/ 400 (Bad Request)
{title: Array(1), abstract: Array(1), attribution: Array(1), doi: 
Array(1), date: Array(1), …}
abstract: ['This field is required.']
attribution: ['This field is required.']
bbox_polygon: ['This field is required.']
constraints_other: ['This field is required.']
data_quality_statement: ['This field is required.']date: ['This field is required.']
date_type: ['This field is required.']
doi: ['This field is required.']edition: ['This field is required.']
embed_url: ['This field is required.']featured: ['This field is required.']
is_approved: ['This field is required.']
is_published: ['This field is required.']language: ['This field is required.']
ll_bbox_polygon: ['This field is required.']
maintenance_frequency: ['This field is required.']
metadata_only: ['This field is required.']
popular_count: ['This field is required.']purpose: ['This field is required.']rating: ['This field is required.']
share_count: ['This field is required.']
srid: ['This field is required.']
supplemental_information: ['This field is required.']
temporal_extent_end: ['This field is required.']
temporal_extent_start: ['This field is required.']
thumbnail_url: ['This field is required.']title: ['This field is required.'][[Prototype]]: Object

enter image description here

4
  • Please Edit the Question place the actual error message in the body of the Question. The reason is two-fold: 1) images are not legible on all devices, and 2) others cannot find your Question with a search on the same or similar message.
    – Vince
    Commented Feb 18, 2022 at 12:38
  • Is this the same as your other question gis.stackexchange.com/questions/423230/… ?
    – KHibma
    Commented Feb 18, 2022 at 13:32
  • @KHibma, I had made progress since that post. I just deleted that earlier post.
    – SharmaPN
    Commented Feb 18, 2022 at 22:50
  • @Vince, done - edited this post with the error.
    – SharmaPN
    Commented Feb 18, 2022 at 22:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.