<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-NZ" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">I am trying to use JavaScript (not Nodejs) to upload a GeoNode document from memory.
<br>
I have tried the JavaScript fetch API from browser. The GET works, but the POST gives error.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Anyone here can direct me how to prevent the required fields error?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">let url = 'https://DOMAIN/api/v2/documents/';<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">let username = 'admin';<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">let password = 'PWD'; <o:p>
</o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">let headers = new Headers();<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">headers.set('Authorization', 'Basic ' + btoa(username + ":" + password));
<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">var crf_token = $('[name="csrfmiddlewaretoken"]').attr('value');<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">headers.set('X-CSRFToken', crf_token);<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">const formData = new FormData()<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">formData.append('newDocumentName', file)<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">headers.set('body',formData) <o:p>
</o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">fetch(url, {method:'POST',<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"> headers: headers<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">})<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">.then(response => response.json())<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">.then(json => console.log(json));<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">Error Message in the Browser console:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">POST <a href="https://DOMAIN/api/v2/documents/">
https://DOMAIN/api/v2/documents/</a> 400 (Bad Request)<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">{title: Array(1), abstract: Array(1), attribution: Array(1), doi:
<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">Array(1), date: Array(1), …}<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">abstract: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">attribution: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">bbox_polygon: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">constraints_other: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">data_quality_statement: ['This field is required.']date: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">date_type: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">doi: ['This field is required.']edition: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">embed_url: ['This field is required.']featured: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">is_approved: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">is_published: ['This field is required.']language: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">ll_bbox_polygon: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">maintenance_frequency: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">metadata_only: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">popular_count: ['This field is required.']purpose: ['This field is required.']rating: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">share_count: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">srid: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">supplemental_information: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">temporal_extent_end: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">temporal_extent_start: ['This field is required.']<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt">thumbnail_url: ['This field is required.']title: ['This field is required.'][[Prototype]]: Object<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><o:p> </o:p></p>
</div>
</body>
</html>