Downloading an Excel File from VLWeb

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Downloading an Excel File from VLWeb

Post by jyoung »

I am creating an Excel file with Integrator and am trying to download it through a Server Module.

Code: Select all

srvroutine name(Download) response(#response)
field_map for(*INPUT) field(#RequestId) parameter_name(RequestId)

#COM_OWNER.CreateExcelFile( #wk_FilePath )

#SYS_APPLN.TraceMessageData( ('Excel File Created At &1').Substitute( #wk_FilePath ) )

#response.ContentFile := #wk_FilePath
#response.AttachmentFileName := 'PTORequest.xlsx'
endroutine
And invoking it as such

Code: Select all

evtroutine handling(#DownloadButton.Click)
define_com class(#PTORequestModule.Download) name(#download) target(New)

#download.Execute requestid(#RequestId)
endroutine
The file is created an the trace output shows it is at "C:\Program Files (x86)\LANSA\X_WIN95\X_LANSA\x_sys\object\MyExcelDocument.xlsx"

The problem is that the download is constantly returning a 404 error.
file_not_found.png
file_not_found.png (16.56 KiB) Viewed 4453 times
I was following along with this post viewtopic.php?f=3&t=194&p=675 but I can't get the error to stop.

I am thinking it may be a permission issue, perhaps IIS (in this case) does not have permissions to the folder?
How can I get the server module to download the File?

EDIT
Tried setting the ContentType to 'application/vnd.ms-excel' thinking that perhaps IIS could not serve XLSX files, that did not work.
Tried writing to the *TEMP_DIR which for me is C:\Windows\Temp and that did not work either, although the File is clearly there.
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Downloading an Excel File from VLWeb

Post by jyoung »

Come to find out there where two problems:
  1. The JSM was experiencing a FATAL error.
  2. Apparently you cannot serve files from *TEMP_DIR


The command causing the FATAL error was this:

Code: Select all

#JSMXCMD := ('SAVE FILE(&1)').Substitute( #filePath )
It should have been this

Code: Select all

#JSMXCMD := ('SAVE FILE("&1")').Substitute( #filePath )
Ugh, notice the quotes around the parameter.

Secondly no matter what I did I could not get a file to be downloaded from *TEMP_DIR, again I think this is due to the permissions of the Temp Folder.

When I moved the file to *PART_DIR it worked finally.
soa
Posts: 339
Joined: Mon Dec 07, 2015 3:15 pm

Re: Downloading an Excel File from VLWeb

Post by soa »

A file can only be downloaded via browser from a folder which is exposed to the public by your web server definition (IIS). You should configure IIS to expose the \temp folder and reference this in the url. You should avoid exposing details about the 'real' locations of data via the web for security reasons.
Post Reply