0

I am trying fetch the PDF file which is return in form of bytes from the API

jQuery:

// jQuery ajax to get fileId and token

window.location.href = "/APIFileDownload/GetFile?fileId= "+ response.fileId + "&token="+ response.token;

C# (ASP.NET MVC)

[HttpGet]
public ActionResult GetFile(string fileId, string token)
{
    // call API with token and file Id
    // get bytes from string reponse
    
    bytes[] fileDownload = Convert.FromBase64String(apiResult.filecontent)
    return File(fileDownload, "application/pdf", "test_download.pdf")
}

Error:

This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.

Please let me know how to return the file from this method.

Amin Sayed
  • 1,240
  • 2
  • 13
  • 26
  • Does this answer your question? [To allow GET requests, set JsonRequestBehavior to AllowGet](https://stackoverflow.com/questions/42206512/to-allow-get-requests-set-jsonrequestbehavior-to-allowget) – Martin Costello Sep 20 '21 at 16:24
  • Are you sure that's *all* your code? You don't have any other code that, maybe, provides a json result if there's an error? eg as in [this question](https://stackoverflow.com/questions/27562046/download-file-in-asp-net-mvc) – freedomn-m Sep 20 '21 at 16:28
  • Yes, this is fine. But my return type is File and not Json(). I cannot put AllowGet in return type File. – Amin Sayed Sep 20 '21 at 16:28
  • Change your action signature to `public FileResult GetFile(string fileId...` and see where it doesn't compile... – freedomn-m Sep 20 '21 at 16:30

0 Answers0