469,353 Members | 2,259 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

Write Error on Upload

This drives me crazy: I have a file upload script to save an image on
the disk (and later on in the database)... it used to work and now it
doesn't, though I didn't change anything within the file upload script
itself.
The file-uploader was originally written by Jacob Gilley and I get the
following error:

Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument
cls-file-uploader.asp, line 139

In this code:

Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
dim n

If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub

Set oFile = oFS.CreateTextFile(sPath & FileName, True)

For nIndex = 1 to LenB(FileData)
n = Chr(AscB(MidB(FileData,nIndex,1)))
oFile.Write n '<------ fires error after some loops
Next

oFile.Close
End Sub

I also tried error handling etc. with no results -- the image saved to
disk will always be around 1K but not the full image. IIS was restarted
several times to no avail.
By the way my upload form looks like this:

<form action="save.asp" method="post" enctype="multipart/form-data">
....
</form>

Can anyone help me? Any help greatly appreciated!

--
Google Blogoscoped
http://blog.outer-court.com
Jul 19 '05 #1
4 10238


Philipp Lenssen wrote:
This drives me crazy: I have a file upload script to save an image on
the disk (and later on in the database)... it used to work and now it
doesn't, though I didn't change anything within the file upload script
itself.
The file-uploader was originally written by Jacob Gilley and I get the
following error:

Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument
cls-file-uploader.asp, line 139

In this code:

Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
dim n

If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub

Set oFile = oFS.CreateTextFile(sPath & FileName, True)

For nIndex = 1 to LenB(FileData)
n = Chr(AscB(MidB(FileData,nIndex,1)))
oFile.Write n '<------ fires error after some loops
Next

oFile.Close
End Sub

I also tried error handling etc. with no results -- the image saved to
disk will always be around 1K but not the full image. IIS was restarted
several times to no avail.
By the way my upload form looks like this:

<form action="save.asp" method="post" enctype="multipart/form-data">
....
</form>

Can anyone help me? Any help greatly appreciated!


Some people run into trouble with the FileSystemObject after installing
some virus scanner or firewall that tries to disable the
fileSystemObject from file access.
As you get some data written that is not likely to be the problem but
check whether you have installed something like that.

As for the error can you debug what value n has when you get
Invalid procedure call or argument
it might be that there is something wrong with that argument.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 19 '05 #2
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Some people run into trouble with the FileSystemObject after installing
some virus scanner or firewall that tries to disable the
fileSystemObject from file access.


Good point.

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com
Jul 19 '05 #3
"Philipp Lenssen" <in**@outer-court.com> wrote in message
news:2n***********@uni-berlin.de...
This drives me crazy: I have a file upload script to save an image on
the disk (and later on in the database)... it used to work and now it
doesn't, though I didn't change anything within the file upload script
itself.
The file-uploader was originally written by Jacob Gilley and I get the
following error:

Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument
cls-file-uploader.asp, line 139

In this code:

Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
dim n

If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub

Set oFile = oFS.CreateTextFile(sPath & FileName, True)

For nIndex = 1 to LenB(FileData)
n = Chr(AscB(MidB(FileData,nIndex,1)))
oFile.Write n '<------ fires error after some loops
Next

oFile.Close
End Sub

I also tried error handling etc. with no results -- the image saved to
disk will always be around 1K but not the full image. IIS was restarted
several times to no avail.
By the way my upload form looks like this:

<form action="save.asp" method="post" enctype="multipart/form-data">
....
</form>

Can anyone help me? Any help greatly appreciated!


FWIW, I wouldn't try to save a binary image file using the text-based
filesystemobject.
http://support.microsoft.com/default...92&Product=asp
http://www.aspfaq.com/show.asp?id=2189

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com
Jul 19 '05 #4
Martin Honnen wrote:

As for the error can you debug what value n has when you get
Invalid procedure call or argument
it might be that there is something wrong with that argument.


I couldn't read out "n" -- it was always showing as an empty string,
but there were some other oddities attached to it I can barely describe!
Thanks for the help to you and others. I finally managed to find
another script to workaround this critical portion of my old script
(which worked for years):

Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex

If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub

Set oFile = oFS.CreateTextFile(sPath & FileName, true)
oFile.Write BinaryToString(FileData) <--- this was the error line

oFile.Close
End Sub

Public Sub SaveToDatabase(ByRef oField)
If LenB(FileData) = 0 Then Exit Sub

If IsObject(oField) Then
oField.AppendChunk FileData
End If
End Sub
' Following via PureASP Uploader ---------------

Function StringToBinary(String)
Dim I, B
For I=1 to len(String)
B = B & ChrB(Asc(Mid(String,I,1)))
Next
StringToBinary = B
End Function

Function BinaryToString(Binary)
'2001 Antonin Foller, PSTRUH Software
'Optimized version of PureASP conversion function
'Selects the best algorithm to convert binary data to String data
Dim TempString

On Error Resume Next
'Recordset conversion has a best functionality
TempString = RSBinaryToString(Binary)
If Len(TempString) <> LenB(Binary) then'Conversion error
'We have to use multibyte version of BinaryToString
TempString = MBBinaryToString(Binary)
end if
BinaryToString = TempString
End Function
Function MBBinaryToString(Binary)
'1999 Antonin Foller, PSTRUH Software
'MultiByte version of BinaryToString function
'Optimized version of simple BinaryToString algorithm.
dim cl1, cl2, cl3, pl1, pl2, pl3
Dim L', nullchar
cl1 = 1
cl2 = 1
cl3 = 1
L = LenB(Binary)

Do While cl1<=L
pl3 = pl3 & Chr(AscB(MidB(Binary,cl1,1)))
cl1 = cl1 + 1
cl3 = cl3 + 1
if cl3>300 then
pl2 = pl2 & pl3
pl3 = ""
cl3 = 1
cl2 = cl2 + 1
if cl2>200 then
pl1 = pl1 & pl2
pl2 = ""
cl2 = 1
End If
End If
Loop
MBBinaryToString = pl1 & pl2 & pl3
End Function
Function RSBinaryToString(xBinary)
'1999 Antonin Foller, PSTRUH Software
'This function converts binary data (VT_UI1 | VT_ARRAY or MultiByte
string)
'to string (BSTR) using ADO recordset
'The fastest way - requires ADODB.Recordset
'Use this function instead of MBBinaryToString if you have
ADODB.Recordset installed
'to eliminate problem with PureASP performance

Dim Binary
'MultiByte data must be converted to VT_UI1 | VT_ARRAY first.
if vartype(xBinary) = 8 then Binary = MultiByteToBinary(xBinary) else
Binary = xBinary

Dim RS, LBinary
Const adLongVarChar = 201
Set RS = CreateObject("ADODB.Recordset")
LBinary = LenB(Binary)

if LBinary>0 then
RS.Fields.Append "mBinary", adLongVarChar, LBinary
RS.Open
RS.AddNew
RS("mBinary").AppendChunk Binary
RS.Update
RSBinaryToString = RS("mBinary")
Else
RSBinaryToString = ""
End If
End Function
Function MultiByteToBinary(MultiByte)
' This function converts multibyte string to real binary data (VT_UI1
| VT_ARRAY)
' Using recordset
Dim RS, LMultiByte, Binary
Const adLongVarBinary = 205
Set RS = CreateObject("ADODB.Recordset")
LMultiByte = LenB(MultiByte)
if LMultiByte>0 then
RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
RS.Open
RS.AddNew
RS("mBinary").AppendChunk MultiByte & ChrB(0)
RS.Update
Binary = RS("mBinary").GetChunk(LMultiByte)
End If
MultiByteToBinary = Binary
End Function

--
Google Blogoscoped
http://blog.outer-court.com
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Amy Kimber | last post: by
6 posts views Thread by Paul | last post: by
6 posts views Thread by Jason Chu | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.