2

I have a REST API that returns application/octet-stream as MediaType and now I need to create a file and download it in client side!

$("#export-space-excel-button").click(function(e) {
    e.preventDefault();
    $("#export-excel-space-dialog").hide();
    $("#export-excel-space-progress-dialog").css("display","");
    $("#export-excel-space-progress-dialog").show();
    $.ajax({
        url :  AJS.contextPath() + "/export/excel/space/"+spaceKey,
        type : "GET",
        data : {data1:data1},
        responseType: 'application/octet-stream',
        contentType: 'application/json',
        success: function(data) {
            const url = window.URL.createObjectURL(new Blob([data]));
            const link = document.createElement('a');
            link.href = url;
            link.setAttribute('download', 'test.xlsx');
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            $("#export-excel-space-progress-dialog").hide();
        }
    });    
});
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Samer SBOUI
  • 21
  • 1
  • 2

0 Answers0