0

I'm trying to convert a file which is located on a remote server. I use ConvertApi for .NET.

My code:

string url = "http://test.com/myfile";
var convertApi = new ConvertApi("secret");
var response = await convertApi.ConvertAsync("web", "pdf", new ConvertApiParam("url", url));

This code fails (ConvertApi returns HTTP 500 Internal Server Error) because the remote server returns HTTP 302 Redirect with the exact file location. But ConvertApi doesn't follow this redirect for some reason.

HTTP 302 Redirect is a very common way for file storage services to handle such downloads.

Is it a bug? Am I missing something? Maybe there is a special setting that forces ConvertApi to follow redirects?

Vladimir Panchenko
  • 1,141
  • 2
  • 15
  • 25
  • What are you trying to convert? Why to pass remote file to web to pdf endpoint? Makes no sence. – Tomas Dec 09 '18 at 21:30
  • I'm trying to convert MS Office documents (docx, doc, etc.) to PDF. MS Office files are located on the external web storage. – Vladimir Panchenko Dec 10 '18 at 09:24
  • I've also tried several other options: `convertApi.ConvertAsync("*", "pdf", new ConvertApiParam("url", url))` and `convertApi.ConvertRemoteFile(url, "pdf", @"C:\Temp")`, but they also throw errors. – Vladimir Panchenko Dec 10 '18 at 09:29
  • And I've tried `convertApi.ConvertAsync("*", "pdf", new ConvertApiFileParam(url))` which works perfectly fine with a direct link, but also fails with Bad Request if the remote server returns 302 Redirect. – Vladimir Panchenko Dec 10 '18 at 12:22

1 Answers1

1

The correct usage to convert remote file is below. You should use ConvertApiFileParam class to pass file as remote file url wrapped into Uri object.

var convertApi = new ConvertApi("secret");    
var sourceFile = new Uri("https://github.com/Baltsoft/CDN/raw/master/cara/testfiles/presentation2.pptx");    
var convertToPdf = convertApi.ConvertAsync("pptx", "pdf", new ConvertApiFileParam(sourceFile));
Tomas
  • 17,551
  • 43
  • 152
  • 257
  • Thanks, but as I told in the last comment, this doesn't help with HTTP 302 Redirect. – Vladimir Panchenko Dec 10 '18 at 15:36
  • 1
    @Vladimir Panchenko The link https://github.com/Baltsoft/CDN/raw/master/cara/testfiles/presentation2.pptx has 302 redirect and it works fine. – Tomas Dec 11 '18 at 08:24
  • Thanks, it worked with this URL. Seems that my file storage provider is specific in some way, I'll investigate it further. – Vladimir Panchenko Dec 11 '18 at 11:08
  • I tried my URL and it seems that it doesn't work - still throws me Internal Server Error. URL for testing: https://vk.com/doc4186592_469942839?hash=b9ead533c7f54eb00b&dl=GQYTQNRVHEZA:1544388563:d9f02fcd6f3c172abb&api=1&no_preview=1 – Vladimir Panchenko Dec 11 '18 at 16:31
  • The ConvertApi support told me that this has been fixed on their side. – Vladimir Panchenko Dec 22 '18 at 17:09