return File get error in api?

mc 3,481 Reputation points

What I want is to download a excel from a api

but I get

PK Æ $Vb eO Gâ
XB ¶*¡ .mÿù~ ù|ÿXo'? LÙQPrYÕR`0d]h ¹YÜÊífý æ È Y ì ã @6 z + ÊKCÉk.ÇÔBÔ¦×-ª®o íwÈÃN±³J¦ ]Jñô ñ nj gð Ìè1ð / ¥Y§ YÉi WJý3Q_ R)à4fuI N Á¢]ÄTæ ;Ì¿"Kæ¡\gÐ1Î ®.I2cfòó ï̬éú|Óßû

such code .

return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");  

I am using ajax post to the api.
I can not download the file why?

A set of technologies in the .NET Framework for building web applications and XML web services.
4,024 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JasonPan - MSFT 3,946 Reputation points Microsoft Vendor

    Hi @mc

    Please try adding responseType in the ajax request. The value of responseType can be arraybuffer, or blob. Code like:

        url: url,  
        method: 'POST',  
        xhrFields: { responseType: 'arraybuffer'}  

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    0 comments No comments