Home > Archive > Programming with dBASE > November 2005 > HTTPFILETRANSFER.CC









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author HTTPFILETRANSFER.CC
Claus Mygind

2005-11-14, 8:23 pm

This application works great with IE. But with FireFox, if the file names
contain blanks the file names are truncated.

when using hyperlinks file names in IE are automatically encoded ie:
My%20File

where as in FireFox the same file would simply appear as My File

Need some help on where to stick in the function "escapeURL( )" by Bowen to
overcome this problem (see code below).
Alternatly I would need a small routine that would read current file names
and replace blanks with "_".


App 1 - Read Dirctory and list available files
aTemporary = new array()
nArraySize = aTemporary.dir(cDir + wkKey)
if nArraySize > 0
for i=1 to aTemporary.size/5
puts(' <TR>')
puts(' <td>')
puts(' <a href="app2.exe? pdfFile='+aTemporary
[i,1]
+'&Loca='+cDir+'">'+aTemporary[i,1]+'</a>')
puts(' </td>')
puts(' </TR>')
next
else
puts('<font color="red">No job records available.</font>')
endif

App 2 - Call HttpFileTransfer when a link is clicked
try
set procedure to HTTPFileTransfer.cc additive
oCGI = new CGIDownload()
oCGI.Connect()
wkFile = oCGI["Loca"]+oCGI["pdfFile"]
catch (exception e)
oCGI.errorPage(e) // trap any errors
quit
endtry

try
oCGI.Download( wkFile, oCGI["pdfFile"] )
catch (exception e)
oCGI.errorPage(e) // trap any errors
endtry
oCGI = null // cleanup
quit

HTTPFILETRANSFER.CC
function Download(cFilePath, cFileName)
local oFile, nBytes,nTotBytes,cBy
tesRead
oFile = new file()
nBytes = oFile.size(cFilePath)
oFile.open(cFilePath, "R")
try
this.fOut.puts("Content-Type: application/x-unknown")
this.fOut.puts("Content-Disposition: attachment;
filename="+cFilename)
this.fOut.puts("")
nTotBytes=0
do
cBytesRead = oFile.Read(1024)
this.fOut.write( cBytesRead )
nTotBytes = nTotBytes + len(cBytesRead)
until nTotBytes = nBytes

oFile.close()
catch (exception e)
nBytes = 0
try
oFile.close()
catch (exception e)
endtry
endtry

return nBytes



Claus Mygind

2005-11-14, 8:23 pm

Now that I think about it, this must be a setting in FireFox, That I should
be able to figure out.

"Claus Mygind" <cmygind@tsccorp.com> wrote in message
news:oWL1EPV6FHA.1288@news-server...
> This application works great with IE. But with FireFox, if the file names
> contain blanks the file names are truncated.
>
> when using hyperlinks file names in IE are automatically encoded ie:
> My%20File
>
> where as in FireFox the same file would simply appear as My File
>
> Need some help on where to stick in the function "escapeURL( )" by Bowen
> to overcome this problem (see code below).
> Alternatly I would need a small routine that would read current file names
> and replace blanks with "_".
>
>
> App 1 - Read Dirctory and list available files
> aTemporary = new array()
> nArraySize = aTemporary.dir(cDir + wkKey)
> if nArraySize > 0
> for i=1 to aTemporary.size/5
> puts(' <TR>')
> puts(' <td>')
> puts(' <a href="app2.exe? pdfFile='+aTemporary
[i,1]
> +'&Loca='+cDir+'">'+aTemporary[i,1]+'</a>')
> puts(' </td>')
> puts(' </TR>')
> next
> else
> puts('<font color="red">No job records available.</font>')
> endif
>
> App 2 - Call HttpFileTransfer when a link is clicked
> try
> set procedure to HTTPFileTransfer.cc additive
> oCGI = new CGIDownload()
> oCGI.Connect()
> wkFile = oCGI["Loca"]+oCGI["pdfFile"]
> catch (exception e)
> oCGI.errorPage(e) // trap any errors
> quit
> endtry
>
> try
> oCGI.Download( wkFile, oCGI["pdfFile"] )
> catch (exception e)
> oCGI.errorPage(e) // trap any errors
> endtry
> oCGI = null // cleanup
> quit
>
> HTTPFILETRANSFER.CC
> function Download(cFilePath, cFileName)
> local oFile, nBytes,nTotBytes,cBy
tesRead
> oFile = new file()
> nBytes = oFile.size(cFilePath)
> oFile.open(cFilePath, "R")
> try
> this.fOut.puts("Content-Type: application/x-unknown")
> this.fOut.puts("Content-Disposition: attachment;
> filename="+cFilename)
> this.fOut.puts("")
> nTotBytes=0
> do
> cBytesRead = oFile.Read(1024)
> this.fOut.write( cBytesRead )
> nTotBytes = nTotBytes + len(cBytesRead)
> until nTotBytes = nBytes
>
> oFile.close()
> catch (exception e)
> nBytes = 0
> try
> oFile.close()
> catch (exception e)
> endtry
> endtry
>
> return nBytes
>
>
>



Claus Mygind

2005-11-18, 11:23 am

I found the proper fix to this problem.

The problem occurs when you have file names with spaces in them ie: My
File.doc.

This is not a problem when using IE but if you are using FireFox the file
name will be truncated to My.

For a better explantion go to this link
http://kb.mozillazine.org/ Filename...br /> _download

The fix is very easy however.
1. Open HTTPFILETRANSFER.CC
2. change the delimiters as follows
Exiting Line:
this.fOut.puts("Content-Disposition: attachment;
filename="+cFilename)
Revised Line:
this.fOut.puts('Content-Disposition: attachment;
filename="'+cFilename+'"')
3. Compile this .cc and any app that references this app and your done.

In other words simply change the existing double quotes to single, then add
closing qoutes after the cFilename variable.


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com