NetTalk Central

Author Topic: Page's _SendFile method is called twice  (Read 102 times)

Thys

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
    • Incasu
    • Email
Page's _SendFile method is called twice
« on: May 14, 2019, 02:29:52 AM »
Hi,

I have an app Integrat that contains a combination of web services and pages. One specific page is called "DownloadFileEx", that receives a parameter "DocumentID" to indicate which document must be downloaded. An example:

http://127.0.0.1:8080/DownloadFileEx?DocumentID=b.txt

 After investigating why the page is not found in the WebHandler procedure, it seems as if p_web._SendFile is called twice - once for "DocumentFileEx" and a second time for the file to be downloaded "b.txt".

When the second call to p_web._SendFile is made for the file to be downloaded, the routine CaseStart:Integrat does not find something called "b.txt" and returns loc:done = false, meaning that the whole request has an error - which is not true. It seams like the logic to call p_web._SendFile a second time in the WebHandler is wrong - shouldn't it be up to the procedure "DownloadFileEx" to retrieve the file?

This was working in NetTalk 10, not sure how to make this work here.

Thanks
Thys

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9566
    • View Profile
Re: Page's _SendFile method is called twice
« Reply #1 on: May 14, 2019, 07:25:45 AM »
Hi Thys,

Perhaps duplicate in Example "File Download (40)" and then send that to me?

cheers
Bruce

Thys

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
    • Incasu
    • Email
Re: Page's _SendFile method is called twice
« Reply #2 on: May 14, 2019, 07:42:53 AM »
Hi,

See attached. I checked again by setting loc:filename to a PEM file that's already in the EXE folder. I added a trace and could see that _SendFile is called twice.

Thanks Bruce.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9566
    • View Profile
Re: Page's _SendFile method is called twice
« Reply #3 on: May 14, 2019, 11:49:11 PM »
You only sent the app - no instructions - but

_SendFile is called for each request that comes into the server. When you click a link on the row there are 2 requests in play (one for the browse-row-clicked event, and one for the call to ServeDocument.

So I'm not seeing what you are seeing... sorry.
Not sure what to do next - perhaps a better example? or more instructions?

cheers
Bruce

Thys

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
    • Incasu
    • Email
Re: Page's _SendFile method is called twice
« Reply #4 on: May 15, 2019, 01:34:01 AM »
Hi Bruce.

Yes, I missed to explain the context of my test. I'm not trying to download a file as part of a web app - rather as part of a set of web services. The web40 demo has a procedure GenerateFile which is similar to the one I've been using in Integrat.

I'm making a call like this (from Postman for API testing) anb expect a file to be received on the client:

http://127.0.0.1:88/GenerateFile

In the procedure of the app I sent, I set the variable loc:filename for the file to be downloaded as a file within the exe folder. Within the procedure, p_web._SendFile is then called twice, and the logic for the second call puzzles me - because the CaseStart: routine won't find a procedure with the same name as the file to be downloaded.

As a last note, this will be used as part of a set of web services, where a client may request to download a file that was previously uploaded or may have been generated by a web service call. So if there is any other way to do a file download, I will like to try it as well. But as said before, this was working perfectly in NT 10, seems it has changed in NT 11.

Thys
« Last Edit: May 15, 2019, 01:48:17 AM by Thys »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9566
    • View Profile
Re: Page's _SendFile method is called twice
« Reply #5 on: May 22, 2019, 11:14:53 PM »
Hi Thys,

Right, I think I understand.

The key is to look at the generated code, specifically the Footer Routine in the GenerateFile procedure. You'll see there a call to

_SendFile(loc:name)

Basically this (GenerateFile) procedure is figuring out the filename, and then calling _SendFile

>> Within the procedure, p_web._SendFile is then called twice,

once with the URL request, which resolves to GenerateFile and the second time as called from GenerateFile.

>>  and the logic for the second call puzzles me - because the CaseStart: routine won't find a procedure with the same name as the file to be downloaded

Correct. But if the WebHandler _SendFile does not find a match (which it won't in this case) then it drops down to the class code in netweb.clw, which in turn reads the file from the disk.

cheers
Bruce