Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1402
  • Last Modified:

Upload file using saFileUp

I'm having trouble uploading file using saFileUp.
I'm getting the file path from a form but the actual saving occurs a few pages later.
The file path is transferd through hidden input fields (though the first input on the first page is through file iput field) because as I said the actual save occur only a few pages forward.
Here is my code:
Set fileUp = Server.CreateObject("SoftArtisans.FileUp")
       Session.CodePage = 1255
       fileUp.CodePage = 1255
       user_file_link = fileUp.Form("myPic").UserFilename
       if Not fileUp.IsEmpty Then
           if fileUp.TotalBytes < 1000000 then  'if the file size is legal (under 1 MB)
                    fileUp.Form("file_link").SaveAs uploadPath + Session("user_name") + "/" + fn
           End if
       End If
The error I get is on this line:
 user_file_link = fileUp.Form("myPic").UserFilename  
and the error is:
 Cannot call BinaryRead after using Request.Form collection.
I have another page which I save files with almost the exact same cose and it works fine
the difference is that I'm getting the file path directly through a file input field and the actual saving occur the next page.
Does it matter? can't see a reason why shouldn't it work using input type hidden.
What am I doing wrong?
Thank u all
  • 8
  • 5
1 Solution

To read a form, there are 2 different methods. And you can not mix those methods.

method 1:
my value = Request.Form("formfield")

method 2:
btValue = Request.BinaryRead

If you use fileupload, the Request.BinaryRead is used. The component uses it.
If you try to use Request.Form("formfield") before or after that, you get an error.

Why use several pages before saving the file ?? Seems so illogical. Why not handle everything in a single page ?
yylexAuthor Commented:
I'm using several pages because there are several input stages.
Each stage is in a different page and gather different types of input.
for example the first page has a form that gather input about the user the following pages gather info about the user's blog (i'm writing a a WebLog application).
One page/form will be too large and illogical.
I can save after each stage but if the user click on the back button or quit anywhere in the middle I don't want to save it. Only on the final stage I want to save all of the data from all stages.
Is there a solution to the fileUp method?
How can I request all other data in a request.BinaryRead?
Will it work alright? 'cus now everything is fine but the saFileUp method
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

in SA-FileUpload you can read all posted formfields with


in stead of Request.Form("formfield")
yylexAuthor Commented:
I have tried to get every single formfiled with
But I get an error:
Error Type:
SoftArtisans.FileUp.1 (0x80020009)
Invalid or corrupt MIME headers. Please check the referring form's ENCTYPE

on the first field I try to read
yeah, you need to post it probably using enctype="multipart/form-data".

or try using this one in stead of SA-FileUp:


that is a lot easier probably
yylexAuthor Commented:
Ok I solved the ENCTYPE problem
I wrote in the form <form ..ENCTYPE="MULTIPART/FORM-DATA">
and all of the data is read ok .
But still I get an error when I want to save
Object required: 'fileUp.Form(...)'

on this line
user_file_link = fileUp.Form("myPic").UserFilename

ofcourse I have an object 'cus I've used it to  read everything else.
yes, but you don't have

"fileUp.Form("myPic")" as an object, because that only is created when there's a file uploaded in the field "mypic".

yylexAuthor Commented:
I do have a field named myPic that came from the same form as input type=hidden
must I use input type=file?
As i said before the file path is read in the first satge with input type=file and transferd to the save page through hidden field?
can't I solve this problem without using input type file?
or maybe there is a way to use hidden field as a file object?
best use some "if" construction, and use only enctype="multipart/form-data" in the form when there is a file upload.

sEncoding = Trim(Split(sRequestContentType, ";")(0))

If sEncoding = "multipart/form-data" Then
    ' use the SA-FileUpload code
    ' use the normal form values
End If
yylexAuthor Commented:
everything works fine with the enctype.
I can read all data using fileUp.Form
when I try to read myPic I get the error
Object required: 'fileUp.Form(...)'

I think it's because the file path comes from a hidden type input field and not input type file.
Is there a way to read the file name using
fileUp.Form("file_link").UserFileName and that the
"file_link" will come not from a file input but from a hidden input?
no, there is no way to tell the type of a formfield after submitting.
But you could try to detect if there's a file in the fields.
Read the documentation of SA-FileUp. It should be esy to solve.

I can tell you how the PseudoRequestDictionary works exactly. http://www.taka.nl/programming/asp/pseudorequest/default.asp
Also my proposal to work with the encoding type should work.
Your analysis of he problem is correct. There are probably many solutions to it.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now