Test Drive It!
Download a fully-functional copy for a test drive at no cost orobligation
For Windows NT/2K Servers
Buy It For US$ 79
Source Code Included
Try-Before-You-Buy Guarantee
Uploading And Validating Files From A Browser To A Server Overview

Most web browsers can submit a file to be uploaded, but whattheweb
server does with the file is an entirely different matter(readhard
to process), particularly when image file properties(e.g.,image
type, size, width, comments, etc.) are involved. Handlingotherfile
types (e.g., MS Access, Excel, Word, HTML, TXT, PDF,ZIP, etc.)have
their own internal structures whose file handlingis definitelynot
for the faint of heart. The FutureWare FileUploadComponent solvesall
of these problems. It can be used wherevera file needs to beuploaded,
such as:
-
Newspapers, for on-line advertising submittals
-
Car dealers, for submitting car images along with price, model,etc.
-
Road warriors, for expense reports, proposals, drafts, etc.
File Property Discovery For Better Asset Management

The FutureWare Web Library's FileUpload component is aserver-sideobjectthat
accepts a file upload from a web browserfor selectedfile types,and
then saving them to the server's filesystem. Foruploaded imagefiles
(i.e., BMP, JPG, GIF and PNG) the objectcanabstract certainimage
properties (e.g., height and width in pixels)forsubsequentprocessing.
For JPG files, the object can additionallyabstracttheCOMMENT and
the 16 application-specific descriptions (i.e.,theAPPnnmarkers)
that can be imbedded within the binary image stream.Theobjectdoes
not allow any modification to any uploaded file.
Server Operating Requirements

The FileUpload object's operating environment is any WindowsNT/2Kserver.It
is included in this FutureWare product distributionasa classobject
for Microsoft's Active Server Pages that is addedasa classto the
server's Registry as an installed DLL, and isbeingused successfullywith
Microsoft's Internet Information Server,O'Reilly'sWebSiteProserver,
and Omnicron Technologies' OHTTPD server,andcan be usedwith Chili!Soft's
ASP products that operate underWindowsNT/2K Servers.
It is also available as a Delphi DCU (included in this FutureWareproductdistribution)that
can be included in any project that usesthe TWebBrokerobject,by
including the object's DCU in the invokingObject Pascalsourcefile
interface usessection.
In addition to web browser uploads of image files, it can also handleMicrosoft'sWordand
Excel documents, text and HTML files.
Fileupload Object's Typical Usage
File uploads are submitted within an HTML form, using the "FILE"inputtype.An
example of such a form is contained in the"fwlfileuploaddemo.html"page,which
would be filled out by auser at a browser that complieswiththe HTML
3.2 specification.
The server processes the form and abstracts the uploaded file,alongwithother
form data, by using the following general steps:
-
Create the FileUpload object
-
Call the object's "AnalyzeContent" method
-
Access and manipulate the object properties as required
-
Call the object's "SaveFileUpload" method
-
Release the object
Examples of how to use the FileUpload object are included in thisFutureWareproductdistribution,
and described in several followingsections.
Restricting File Type Submittals At The Client
File submittals from a browser client can be restricted to specificfiletypes
by a
javascript function invoked on the form's
OnSubmitevent,
which isdescribed in the includedreference document and includedin
the demo HTML pages.
Accessing Form Data
Most servers have a read-forward-only mode of retrieving formdata,suchas
name-value pairs. To avoid possible loss, formdata shouldnotbe accessed
directly from the server's requestobject, but insteadaccessedthrough
the FWLFileUpload object'sseveral form propertiesafter theobject
has been created andthe "AnalyzeContent" methodhas been invoked.
Form Design Requirements
An example of a form that invokes the FWL FileUpload object iscontainedinthe
"fwlfileuploaddemo.html" page, which has to havethe form'sACTIONvalue
set to the appropriate web server target(ASP or DLLas noted).Additionally,
the following declaration mustbe includedin the FORM'sattributes
section:
ENCTYPE="multipart/form-data".Ifthisdeclaration
is missing then the error message "3: No Content"willoccuras noted
in the "sErrorMessage" property described below.
ASP Script Example
The ASP script "fwlfu_asp_demo.asp" gives an example of how theFWLFileUploadobject
can be used in an interpreted ASP environment.ThisASP scriptcan
be invoked from the "fwlfu_asp_demo.html"page byreplacing the'asp_demo_path_here'
placeholder with theserver pathto the foldercontaining the "fwlfu_asp_demo.asp"
script.
ISAPI/NSAPI Example
The Delphi project "FWLFU_DelphiDemo.dpr" gives an example of howtheFWLFileUpload
object can be used in an ISAPI/NSAPI environment.The"uFWLFU_DelphiDemo.pas"source
file contains the Object Delphicode as asample of how touse the
Delphi version of the FileUploadobject. Thisdll can be invokedfrom
the "fwlfu_delphi_demo.html"page by replacingthe 'delphi_demo_path_here'placeholder
with theserver path to thefolder containing the "FWLFU_DelphiDemo.dll"file.
Properties
The FWL FileUpload object has eight read-only properties that havevalidvaluesonly
after the "AnalyzeContent" method (described below)hasbeeninvoked.
sErrorMessage: string
If an error is detected during either the "AnalyzeContent" or "SaveFileUpload"methodsthen
this property will describe the error. If no erroris detectedthen
this property will be empty. The number precedinga colon willbe
the error number; the error description will followthe colon.The
possible error numbers and messages are:
-
0: FWL Object Not Registered
-
1: Exceeds FileSize Limit
-
2: ClientRead Error
-
3: No Content
-
4: Incomplete Content
-
5: Missing Content
-
6: No File To Save
-
7: Uknown FileType
-
8: Boundry Missing
-
9: [SystemErrorMessage]
sFileName: string
Valid after the "AnalyzeContent" method call, the name of the fileuploadedwith
its file extension. The case of the file name isnot alteredin any
way. Set to UNK if the file is not a recognizedMIME type.
iFileSize: integer
Valid after the "AnalyzeContent" method call, the size of the uploadedfile.Set
to 0 if the file is not a recognized type (i.e., BMP,JPG, GIF,PNG,
DOC, TXT, XLS or HTML).
sFileType: string
Valid after the "AnalyzeContent" method call, describes the uploadedfileextension:
-
JPG: JPG (or JPEG as JPG) image file
-
GIF: GIF (87a or 89a) image file
-
PNG: Portable Network Graphics image file
-
DOC: MS Word file
-
TXT: ASCII Text file
-
XLS: MS Excel spreadsheet file
-
HTML: HTML file
-
ZIP: ZIPed file
-
UNK: Unknown
iFormElementCount: integer
Valid after the "AnalyzeContent" method call, the number of formelementnames
which have non-empty associated values.
iImageHeight: integer
Valid after the "AnalyzeContent" method call and only for BMP,JPG,GIF
and PNG image files, indicates the first image's heightin pixels.For
GIF image files, this is the height of the logicalscreen.
iImageWidth: integer
Valid after the "AnalyzeContent" method call and only for BMP,JPG,GIF
and PNG image files, indicates the first image's widthin pixels.For
GIF image files, this is the width of the logicalscreen.
sJPGComment: string
Valid after the "AnalyzeContent" method call and only for JPG imagefiles,the
JPG's imbedded comment string (i.e., the COM marker),if any.
Methods
The FWL FileUpload object has five methods that return a value.TheDelphiTWebModule
version of the object has a sixth method, beingtheCreate(),which
does not return a value.
function AnalyzeContent: boolean
Called after the FWL FileUpload object is created, analyzes thewebrequest
object's payload for analysis and parsing. Returns TRUEifno problems
were encountered, FALSE otherwise. If returns FALSEthenthe "sErrorMessage"
property will describe the error as notedabove.
procedure Create
For the Delphi TWebModule version only, creates the object andpreparesthe
web request object's payload for analysis and parsing.Must bedone
before the "AnalyzeContent" method call is used. Theobjectmust be
explicitly released before exiting from the TWebModuleprocessingsection.
function sJPGAppData(ziAppIndex: integer): stringValidafter
the "AnalyzeContent" method call and only for JPG imagefiles,returns
the "Application" description (i.e., the APP0 throughAPP15markers)
for the "ziAppIndex" value, which can range from'0' to'15'. By convention,
'0' usually returns the string "JFIF".
function sFormElementName(ziIndex: integer): stringValidafter
the "AnalyzeContent" method call, returns the formelementname, indexed
by the "ziIndex" integer argument, that hasa non-emptyassociated
value. The first element's index is '1',and the lastindex is the
value in the "iFormElementCount" property.Returns anempty string
if the "ziIndex" integer argument is eitherzero orexceeds the "iFormElementCount"
property value.
function sFormElementValue(zsName: string): string
Valid after the "AnalyzeContent" method call, returns the valueassociatedwith
the form element name, as a string. as specifiedin the "zsName"string
argument.
function SaveFileUpload(zsFilePath: string): boolean
Valid after the "AnalyzeContent" method call, saves the uploadedfileas
completely specified in the "zsFilePath" argument. ReturnsTRUEif
the uploaded file was saved, FALSE otherwise. If returnsFALSEthen
the "sErrorMessage" property will describe the erroras notedabove.
**NOTE: XLS AND DOC FILES SHOULD BE CHECKED FORPOSSIBLE HARMFULMACROS
AND SCRIPT EXECUTIONS BEFORE THEY ARE MADEAVAILABLE TO THEAPPLICATION
ENVIRONMENT **
Have any
questions
on FutureWare'sWeb Library FileUpload Component?
Whether by email or phone, we'd be happy to answer them for you.
FutureWare: Doing Windows, filling Pockets, and reading Palms,
Making Software That Works! For Health, Home And Office
www.futurewaredc.com 775.346.8185 skype: FutureWareSCG
We Succeed When You Do. Since 1984