Forum Moderators: open
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
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
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
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.
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