?
Solved

Upload file using saFileUp

Posted on 2003-03-23
13
Medium Priority
?
1,358 Views
Last Modified: 2009-07-29
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)
                    fn=Mid(user_file_link,InstrRev(user_file_link,"\"))
                    fn=right(fn,len(fn)-1)        
                    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
0
Comment
Question by:yylex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 8189746
Because:

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.


0
 
LVL 28

Expert Comment

by:sybe
ID: 8189747
Why use several pages before saving the file ?? Seems so illogical. Why not handle everything in a single page ?
0
 

Author Comment

by:yylex
ID: 8189773
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
Thanks
0
Independent Software Vendors: 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!

 
LVL 28

Expert Comment

by:sybe
ID: 8189787
in SA-FileUpload you can read all posted formfields with

fileUp.Form("formfield")

in stead of Request.Form("formfield")
0
 

Author Comment

by:yylex
ID: 8189849
I have tried to get every single formfiled with
fileUp.Form("formfield")
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
0
 
LVL 28

Expert Comment

by:sybe
ID: 8189862
yeah, you need to post it probably using enctype="multipart/form-data".

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

http://www.taka.nl/programming/asp/pseudorequest/default.asp

that is a lot easier probably
0
 

Author Comment

by:yylex
ID: 8189915
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
error:
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.
0
 
LVL 28

Expert Comment

by:sybe
ID: 8189928
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".

0
 

Author Comment

by:yylex
ID: 8189956
hmm....
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?
0
 
LVL 28

Expert Comment

by:sybe
ID: 8190774
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
Else
    ' use the normal form values
End If
0
 

Author Comment

by:yylex
ID: 8191607
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?
0
 
LVL 28

Expert Comment

by:sybe
ID: 8193005
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
0
 
LVL 28

Accepted Solution

by:
sybe earned 180 total points
ID: 8193009
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.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question