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