Download PDF file by link in e-mail

Asked

Viewed 279 times

2

I developed a function that passing the Item id it generates a PDF file.

[HttpPut]
public void GerarPDF(long idItem)
{
....Função
}

It already works perfectly, I did the test through the Google Chrome app called Postman, and passing the path it generates the PDF and download everything straight, but if I send this same path in the body of an email through a <a></a> so that the person who received the email can generate the PDF, this path does not work:

"<a href=http://localhost:11599/Item/GerarPDF?idItem=" + IdItem.ToString() + "> link Download PDF </a>"

Making the following mistake: inserir a descrição da imagem aqui

Now I don’t know if it’s because I’m trying to open by localhost or not, if anyone can help me thank you.

  • Have you tried hosting at any address other than localhost to see if it works?

  • I will do this, I believe it is due to the same localhost.

  • 1

    Is your system hosted or just on localhost? Does your email work on your computer? Remove the [HttpPut] or change to [HttpGet]

2 answers

5

An anchor (<a href ...>) will always send a GET pro server.

This is the problem, the action is responding to requests PUT and not GET.

Just change the attribute of [HttpPut] for [HttpGet] will cause the action to be called.

[HttpGet]
public void GerarPDF(long idItem)
{
}

1


I use it like this to download.

public FileResult DownloadAnexo(int id)
{
    string URL = //BUSCAR URL ARQUIVO DESEJADO;
    return File(URL, "multipart/mixed", "Nome_SeuArquivo");
}

Note that the return is a FileResult

  • Thanks friends, I made a combination with your tips and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.