Error 404 when downloading PDF

So I have a web app. I offload the generation of PDF outputs to helper apps. The helper app returns the file name, and then I return this file to the user. or so is the plan.

The webapp is standalone on Windows (result is the same on 8.1 and 10) compiled 32 bit.
I have the same in the IDE on Windows 10.
Xojo 2017 R2

my app uses webcontainers, not pages. So:

  • The webfile is a property of the webcontainer.
  • The generation of the PDF is handled by the helper app, so this all happens with a shell. I use a handler method on the webcontainer to perform the data available event. Here is the code in the handler method:

[code]’ method sCompL_DA
System.debuglog (“Entering method sCompL_DA”)

Dim CList As String
CList = sPCList.ReadAll
Clist = Trim(CList)
Clist = ConvertEncoding(CList, encodings.UTF8)

'Find printed PDF dicument
Dim fPDF As folderitem
fPDF = New FolderItem(SpecialFolder.Documents.Child(CList))

System.debuglog ("Looking for file: " + fPDF.NativePath)

'Open and show printed document
If fPDF <> Nil And fPDF.Exists Then

System.debuglog ("fPDF NativePath: " + fPDF.NativePath)

Self.PDFFile = WebFile.Open(fPDF)
Self.PDFFile.UseCompression = False
Self.PDFFile.ForceDownload = True
System.debuglog (“Folderitem does not exist”)
End If

If Self.PDFFile <> Nil Then

System.debuglog ("PDFFile: " + Self.PDFFile.URL)

System.debuglog (“Webfile does not exist”)
MsgBox(“The PDF file is not available.”)
End If

'reinitialize document variables
Self.PDFFile = nil
fpdf = Nil

'remove handler
RemoveHandler sCompL.DataAvailable, AddressOf sCompL_DA[/code]

  • dbgview reports the following notes:

[3188] Entering method sCompL_DA [3188] Looking for file: C:\\Users\\WEBSVRADMIN\\Documents\\redbook20162017eng.pdf [3188] fPDF NativePath: C:\\Users\\WEBSVRADMIN\\Documents\\redbook20162017eng.pdf [3188] PDFFile: /_files/1848-2687-0187-9593-8189/redbook20162017eng.pdf

It seems that all goes well until I assign the folderitem to the webfile. PDFFile is the webfile in the code above. I get Error 404 instead of the download that I would expect. Is this an error on my part, or did I just happen to stumble on a bug?

Any insight into this problem is welcome!


Check if the folderitem.exists = True on the PDFfile

Thank you Derk. Your suggestion will certainly remove the 404 problem, but instead I will probably end up with a missing PDFFile folderitem. Is it possible that the PDFFile URL is malformed?

EDIT: Actually, I check that fPDF exists and is not nil before doing the assignment to PDFFile. So in effect, the folderitem does exist. It appears that the whole issue is at the webfile level.

Do use:

Dim fPDF As Folderitem = Specialfolder.Documents.Child( Clist )

And youbrove the handler but are you sure all the data is received?
Also Paths can have spaces, try to send them quoted?

Self.PDFFile, overlooked it. You use Self. Perhaps it’s better to have Cotainername.PDFfile = Webfile.Open…

That would indeed be more elegant, but I believe that the folderitem is OK. redbook20162017eng.pdf (contained in CList) is the data sent from the shell process. I am certain that it is received, since I have it and it is exactly what the helper app sends.
The folderitem is (as per dbgview) C:\Users\WEBSVRADMIN\Documents\redbook20162017eng.pdf. I check that this exists and is not nil. I can also see the file exactly there in Explorer. I honestly believe that the problem comes after the folderitem.

This is one thing I haven’t tried yet. Will do!


Perhaps it’s what you suggested;
ShowURL( App.URL + Self.PDFfile.URL )

follow up:

  • containername.pdffile will not work. The actual container is created in code as an instance of the base model container. Therefore, the container name is not known at design time and this is not going to compile.
  • App.URL is an empty string (at least in the IDE), so this is not solving the problem either.

I reinstalled 2017 R1.1 and tried. This is to eliminate a R2 bug. 2017 R1.1 generates the same error.

After playing with it for a while, I came to the conclusion that my specific scenario is not supported.


Another approach you could take is just set up your web app to serve static files. Then you can just set a Link to the file.

Some open source code here to serve static files like PDF from Xojo Web easily:

Thank you Phillip! I already downloaded the tool. I am certainly going to take a good look it.

For everyone’s benefit, as per @Greg O’Lone comment in the feedback case. The issue was caused by my own code. I am in a habit of cleaning up after myself, and that is precisely what caused the problem. I forgot that things happen at the end of a method in a web app. This code

'reinitialize document variables Self.PDFFile = nil fpdf = Nil
towards the end of my method, effectively killed the webfile before it was presented to the browser.