ConvertAPI / convertapi-library-dotnet

A .NET library for the ConvertAPI
https://www.convertapi.com
Other
22 stars 8 forks source link

Help with the ConvertAsync Status WaitingForActivation #13

Closed eduarmreyes closed 5 years ago

eduarmreyes commented 5 years ago

Hello, I have been having issues with the code examples to convert a file from docx to pdf using convertapi-dotnet.

The part where ConvertApiResponse result = response.Result; is executed never ends for a reason I don't fully understand.

Any way somebody can help me with these?

image

I tried with VS 2019 .net v=4.7.2 and VS 2015 .net v=4.5.2 but don't seem to actually convert the file, though. 😩.

tomasr78 commented 5 years ago

Do you use it form ASP.NET? It could be that library can't post to our rest api service. Check your permissions.

eduarmreyes commented 5 years ago

Do you use it form ASP.NET? It could be that library can't post to our rest api service. Check your permissions.

Yes, I am using it from ASP.NET, that is actually my guess, do you mind helping me understand where to check my permissions? 🤔

tomasr78 commented 5 years ago

Do you run from the local pc?

eduarmreyes commented 5 years ago

Do you run from the local pc?

Yes, I do run from the local PC.

My workstation looks like this:

Created a new account not long ago, this is how my statistics look like.

image

This is how my code looks like.

[HttpPost]
// [ValidateAntiForgeryToken]
public ActionResult Index(string fromFormat, string toFormat, HttpPostedFileBase file)
{
  if (fromFormat == "")
  {
    ViewBag.Message = "From format is required";
    return View();
  }

  if (toFormat == "")
  {
    ViewBag.Message = "To format is required";
    return View();
  }

  if (file == null || file.ContentLength <= 0)
  {
    ViewBag.Message = "File is required";
    return View();
  }

  if (fromFormat == toFormat)
  {
    ViewBag.Message = "The 'from' and 'to' files types are the same.";
    return View();
  }

  ConvertApi convertApi = new ConvertApi(Properties.Settings.Default.CONVERT_API_SECRET);

  try
  {
    string path = Path.Combine(
      Server.MapPath("~/Files"),
      Path.GetFileName(file.FileName));

    file.SaveAs(path);

    var response = convertApi.ConvertAsync(fromFormat, toFormat,
      new ConvertApiFileParam(@path)
    );

    ConvertApiResponse result = response.Result;

    result.SaveFile(Server.MapPath("~/Files"));

  }
  catch (Exception ex)
  {
    ViewBag.Message = "ERROR: " + ex.Message.ToString();
  }
  return View();
}
tomasr78 commented 5 years ago

The problem lies in Asynchronous handling in ASP.NET Web Forms. Please find the solution on how to use Async in ASP.NET at StackOverflow https://stackoverflow.com/a/56687401/281014