POST JSON + File with formData

Hi! Im trying to send a Json and a File inside a Form Data.

  1. Is this syntax correct?
  2. Also, how can I see the formData that I’m sending?
<div id="id_show_upload_csv" style="display: none; padding-left: 10px;">
  <form class="form-group"  id="div-upload-csv">
    <input type="file" id="fileupload" name="fileupload" accept=".csv">
  async function uploadFile(url = '', data = {}, extraHeaders = {}) {
    let formData = new FormData(); 
    for (const [k, v] of Object.entries(data))
    formData.append(k, v)
    formData.append("fileupload", fileupload.files[0]);

    const response = await fetch(url, {
      method: 'POST', 
      mode: 'cors', 
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${localStorage.getItem('jwtToken')}`,
        'X-CSRFToken': '{{csrf_token}}',
      body: formData
    return formData
  uploadFile('/secret/admin/marketing/proxy/', dataToSend, { 'url': 'sms/api/campaign/create/' })

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.