I am trying to download audio or video but shows this error.

Here is the code please check this code.

$.ajax({
        url: 'https://cdn.shopify.com/s/files/1/0518/1269/6219/files/sample-3s.mp3',
        method: 'GET',
        async:true,
        crossDomain:true,
        headers:{'Content-Type':'audio/mpeg','X-Requested-With':'XMLHttpRequest'},
        processData: false,
        dataType: 'binary',
        xhrFields: {
          responseType: 'blob'        
        },
        success: function (data) {
            var a = document.createElement('a');
            var url = window.URL.createObjectURL(data);
            a.href = url;
            a.download = 'sample-3s.mp3';
            document.body.append(a);
            a.click();
            a.remove();
            window.URL.revokeObjectURL(url);
        }
    });
});

Hi @ksuman ,

Please change code:

fetch('https://cdn.shopify.com/s/files/1/0518/1269/6219/files/sample-3s.mp3')
  .then(resp => resp.blob())
  .then(blob => {
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;
    // the filename you want
    a.download = 'sample-3s.mp3';
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
    alert('your file has downloaded!'); // or you know, something with better UX...
  })
  .catch(() => alert('oh no!'));

Hope it helps!