Forum Moderators: open

Message Too Old, No Replies

How Upload.form works

         

Maria

11:16 am on Feb 6, 2003 (gmt 0)

10+ Year Member



Hello;

I am trying to upload a file and send it via email as an attachment. When I type the email address on the code everything work fine but when I add a input text to the form to enter the email address I can not use the request.form command, so I use upload.form instead but is giving me the "Object required: 'Upload'" error.

Could you please help me? What am I doing wrong?
Is the syntax like this upload.form("file")?

I appreciated any help
Maria

wardbekker

11:40 am on Feb 6, 2003 (gmt 0)

10+ Year Member



Hi Maria,

Did you name the upload object variable also upload? For example: if you named it

Set oUpload = Server.Create...

oUpload.form("strFileName")?

On a sideNode, naming your textbox element "filename" can cause sometimes problems with a old version of a particular upload component

Maria

12:19 pm on Feb 6, 2003 (gmt 0)

10+ Year Member



Hello Wardbekker;
Thank you very much for you prompt answer.

With your answer I realized that I don’t know how the upload object supposed to work. Here is the code that I found in a web site and that I am using to upload files, which is working fine, but I do not know which is the object that is uploading. I tried MyFileObject, objFile and UploadRequest but any of them work. Do I have to create another object? If so which object is it? Set upload= server.createobject(“? ”). Thank you again for your help, I really appreciated it.

If request("Action")="1" then
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)

Set UploadRequest = CreateObject("Scripting.Dictionary")

BuildUpload(RequestBin)

If UploadRequest.Item("blob").Item("Value") <> "" Then

contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
FolderName = UploadRequest.Item("where").Item("Value")
Path = Mid(Request.ServerVariables("PATH_TRANSLATED"), 1, Len(Request.ServerVariables("PATH_TRANSLATED")) - Len(Request.ServerVariables("PATH_INFO")))
ToFolder = Path & "\" & FolderName
value = UploadRequest.Item("blob").Item("Value")
filename = ToFolder & "\" & filename
Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject")

Set objFile = MyFileObject.CreateTextFile(filename)

For i = 1 to LenB(value)
objFile.Write chr(AscB(MidB(value,i,1)))
Next
objFile.Close
Set objFile = Nothing
Set MyFileObject = Nothing
End If
Set UploadRequest = Nothing
end if

wardbekker

12:48 pm on Feb 6, 2003 (gmt 0)

10+ Year Member



This is a script for uploading a file without the need of an upload component.

The object that contains the request.form values is probably UploadRequest, but because the code for BuildUpload is missing, i can't determin what the correct code should look like.

Maria

2:17 pm on Feb 6, 2003 (gmt 0)

10+ Year Member



Sorry Wardbekker; I did not copy the BuildUpload function because it too big and I thought it was not necessary. But here it is. Thanks.

Function BuildUpload(RequestBin)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) Then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Function

wardbekker

9:24 pm on Feb 6, 2003 (gmt 0)

10+ Year Member



Maria,

I took a quick look at the code, but i think you can't use this script if you need values of other form fields a well. You might want to try out out an asp upload component. Such components offer much better server-side performance and you can access other form field values even when uploading a file.

RZaakir

4:55 pm on Feb 12, 2003 (gmt 0)

10+ Year Member



I fought with this very thing a few weeks ago. The pure ASP method should ONLY be used as a last resort. It is DOG SLOW. This is because it has to loop through the data being uploaded bit by bit and creates a tremendous bottlneck (a 100Mbps Ethernet connection uploads at the same speed as a 256k aDSL connection... and I'd speculate that a 56k modem wouldn't be any faster). It also hampers you because files that any appreciable size ( > 30k) can cause your application to timeout unless you dynamcally change the value of your scripttimeout variable.

The problem with using a COM object is that 1) most people want you to pay for it and 2) if you're not in control of your own servers, you're at the mercy of your ISP in whether you'll be able to register it on your server or not.

The solution to #1 is here:
[vbweb.co.uk...]

It's a free COM object that lets you upload files in a fast and efficient manner while maintaining the other form values. It has all of the basic functionality that you will probably need if you've been trying the Dictionary method.

Issue #2 is in your hands. If your ISP doesn't provide an upload component and won't let you register one, you may want to either change ISP's or possibly use perl / CGI for file uploads.

Hope that helps.
Rashid

Maria

5:08 pm on Feb 12, 2003 (gmt 0)

10+ Year Member



Thank you very much Rashid;

You have answered all my questions.

I appreciated.

Maria