Cannot use Request.Form

  • Thread starter Christopher Brandsdal
  • Start date
C

Christopher Brandsdal

Hi!

I get an error when I run my code
Is there any other way to get te information from my form?

Heres the error I get and the code beneath.
Line 120 is market with ''''''''''''Line 120'''''''''''''''''''''


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''CODE'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Request object error 'ASP 0207 : 80004005'
Cannot use Request.Form

/asp/admin/select_image.asp, line 120

Cannot use Request.Form collection after calling BinaryRead.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''CODE'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

if Request.QueryString("action") = "upload" then
Server.ScriptTimeout = 1200
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")

ByteCount = Request.TotalBytes

if ByteCount > Application("MaxFileSize2Upload") then
Response.Redirect "./select_image.asp?error=05"
end if


RequestBin = Request.BinaryRead(byteCount)
BuildUploadRequest RequestBin

Dim aux, aux1
Dim ImageCateg, ContentType, FilePathName, FileName, Value

ImageCateg = Unescape(UploadRequest.Item("inpcatid").Item("Value")) 'Image
Folder

on error resume next
ContentType = UploadRequest.Item("inpFile").Item("ContentType")
FILEFLAG = err.number
on error goto 0

if FILEFLAG = 0 then
ContentType = UploadRequest.Item("inpFile").Item("ContentType")
FilePathName = UploadRequest.Item("inpFile").Item("FileName")
FileName =
Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
Value = UploadRequest.Item("inpFile").Item("Value")
else
FileName = ""
end if

Dim objFSO2
Dim objFSO3
Dim objUploadFile
Dim objDelFile1
Dim OldPath
'''''''''''''''laster opp bilde'''''''''''''''''''''''''''''
if FileName<>"" then
on error resume next
Set objFSO2 = Server.CreateObject("Scripting.FileSystemObject")
Set objUploadFile = objFSO2.CreateTextFile(ImageCateg&"\"&FileName)
objUploadFile.Write getString(value)
objUploadFile.Close
FILEFLAG = err.number
on error goto 0
'''''''''''''''resizer bilde'''''''''''''''''''''''''''''
' create instance of AspJpeg object
Set jpeg = Server.CreateObject("Persits.Jpeg")

' open uploaded file
Dim ResizeName
Dim Ratio
OldPath = Server.MapPath(Escape(sDir) & Escape(FileName))
jpeg.Open( OldPath )
' resize image accoring to "scale" option.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''Line
120'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''
Select Case Request.Form("resize")

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''/Line
120/''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''
Case "tn"
ResizeName = "_miniatyr"
Ratio = jpeg.OriginalHeight / 100
jpeg.Width = 100
jpeg.Height = jpeg.OriginalHeight / Ratio
Case Else
ResizeName = "_noko_anna"
jpeg.Width = jpeg.OriginalWidth * 50 / 100
jpeg.Height = jpeg.OriginalHeight * 50 / 100
End Select
OldPath = Server.MapPath(Escape(sDir)) & "\" & Escape(FileName)
SavePath = Left(OldPath, InStrRev(OldPath, ".") - 1)
SavePath = SavePath & ResizeName
SavePath = SavePath & ".jpg"
Jpeg.Interpolation = 2
'AspJpeg always generates JPEG thumbnails regardless of original format.
'If the original file was not a JPEG, append .JPG extension.

jpeg.Save SavePath
end if

Set objFSO2 = nothing
Set objUploadFile = nothing
Set UploadRequest = nothing
 
A

A Ratcliffe

BinaryRead and Request.Form/QueryString are mutually exclusive. Once you
have used one to read the data, the other is inaccessible.

I found an article on the MSDN library about how to recreate a
pseudo-Request.Form collection but its taken from Active Server Developer's
Journal, so I'm not sure if its on the web. I'll see if I can find a web
article on this, otherwise I'll have a read through the article and give you
the basics here.

A Ratcliffe
(e-mail address removed)
 
C

Christopher Brandsdal

Thanks for helping me!

I think it's possible because AspUpload can do it.

I have AspJpeg installed on my server but NOT AspUpload.
Here is a short AspJpeg script that use something else than Request.Form:

<HTML>
<HEAD>
<TITLE>AspJpeg 1.2 - Upload.asp</TITLE>
</HEAD>
<BODY>

<!-- this script is invoked by form.asp-->
<%
' Create an instance of AspUpload object
Set Upload = Server.CreateObject("Persits.Upload")

' Capture uploaded file. Save returns the number of files uploaded
Count = Upload.Save(Server.MapPath("/"))

If Count = 0 Then
Response.Write "No images selected. <A HREF=""form.asp"">Try again</A>."
Response.End
Else

' Obtain File object representing uploaded file
Set File = Upload.Files(1)

' Is this a valid image file?
If File.ImageType <> "UNKNOWN" Then

' create instance of AspJpeg object
Set jpeg = Server.CreateObject("Persits.Jpeg")

' open uploaded file
jpeg.Open( File.Path )

' resize image accoring to "scale" option.
' notice that we cannot use Request.Form, so we use Upload.Form instead.
jpeg.Width = jpeg.OriginalWidth * Upload.Form("scale") / 100
jpeg.Height = jpeg.OriginalHeight * Upload.Form("scale") / 100

SavePath = Server.MapPath("/bilde/") & File.ExtractFileName

' AspJpeg always generates JPEG thumbnails regardless of original format.
' If the original file was not a JPEG, append .JPG extension.
If UCase(Right(SavePath, 3)) <> "JPG" Then
SavePath = SavePath & ".jpg"
End If

jpeg.Save SavePath

Response.Write "Success! Both the original file and its thumbnail are
saved in the database.<P>"
Response.Write "Copies can be found at <B>c:\upload\" &
File.ExtractFileName & "</B> and <B>" & SavePath & "</B>"

Else
Response.Write "This is not a valid image. <A HREF=""form.asp"">Try
again</A>."
Response.End
End If
End If
%>
</BODY>
</HTML>
 
A

A Ratcliffe

It's definitely possible (the article I mentioned shows how to do so, which
is probably how ASPUpload does it).
 
C

Christopher Brandsdal

Thank you :)
When I read the article I thought.... AHA!
hehe
The problem is solved, and I am happy as a butterfly ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top