View Full Version : Uploading problem, please help!
JGizmo
01-28-2003, 03:26 PM
Hi all,
I have a flash needed for upload image to server from html to cgi/pl to mysql. Most of the details is working like the browse window button and the perl script.
But....:( ..........when I use sendAndLoad, MX seems to rush though the perl code and ignore the bit (read whole file and create new file with full size), it did actually create a new file but with 0 byte!.........the most :mad: bit is when I using the same perl script inside html instead of call it from flash, IT WORKS!
Anyway, if anyone had this problem before, please share..
here is some of the AScode I had:
sd = new LoadVars();
sd.FILE1 = filename;
rLv = new LoadVars();
sd.sendAndLoad("http://www.xxxxxx.com/upload.pl", rLv);
rLv.onLoad = function(success) {
if (success) { msg.text = this.mymsg;
saved = this.mysaved;
}
And I am sure I am passing the same type of data from flash to cgi as from html browse button to cgi.
Thanks in advance
pichto
01-28-2003, 07:07 PM
Try that :
sd = new LoadVars();
sd.FILE1 = filename;
rLv = new LoadVars();
sd.sendAndLoad("http://www.xxxxxx.com/upload.pl", rLv, "POST");
//notice the POST statement in the line above
rLv.onLoad = function(success) {
if (success) { msg.text = this.mymsg;
saved = this.mysaved;
}
}
Anyway, could tell us a bit more about how you call your Perl script with a browser ?(Form, GET method, etc...) Maybe we can find a solution looking in this way...
JGizmo
01-29-2003, 04:02 PM
Sorry haven't make that clear.
Perl script that I used is an open source script, it works well when I use it with html's form with post method and it will return content-type as html text for feedback messages such as file extension wrong, been saved...etc
However, I needed this script to work in my flash, I want flash to recieve these feeback too but as param messages, so I rewrite some of the perl feedback script ( but this is not why the script arnt working ) ......so I use the sendAndLoad method. I also notice whether I use post or without the post method in the AS code, the sendAndLoad method will send it as POST method to server but the other one just create an "blank" html page!?
Anyway, my problem is the data send to perl script and return the right feedback to flash and it will create file but with 0 bytes everytime, so I think something wrong with my as script that not making the "send" connection long enough to upload the whole file before "load" method comes in. But how come it works fine in html form which I just cant understand.
Thanks
John
pichto
01-29-2003, 07:10 PM
Are you sure that your perl script should only receive the filename as parameter. Maybe it has to receive something to put in it... because with your loadVars object you only (in your case) send the filename (sd.FILE1 = filename;)
Anyway could you tell us how your perl works : does it receive only the filename and prompts for content or does it have to receive all at once?
First you can maybe try a little thing :
use that AS code :
getURL("http://www.xxxxx.com/upload.pl?FILE1="+filename,"_blank");
And comment all the other lines.
P.S. : are you sure FILE1 is the name of the variable perl should receive. It's not really common for that kind of things...
P.P.S : Maybe the error is here, check that out :
sd = new LoadVars();
sd.FILE1 = filename;
rLv = new LoadVars();
sd.sendAndLoad("http://www.xxxxxx.com/upload.pl", rLv, "POST");
//notice the change for the onLoad function. sd calls the command
//so, sd should wait for the answer...
sd.onLoad = function(success) {
if (success) { msg.text = rLv.mymsg;
saved = rLv.mysaved;
}
}
JGizmo
01-30-2003, 01:09 PM
Hi pichto,
Still cant get this upload thing working in flash :(
But the suggestion you made is very helpful, special the getURL debug method, I tried that.....and from the perl script debug come back both (from html form or from flash) come back the same input for param (FILE1 has the same value.....SO very weird why its not working in flash!) means that they are sending the same value to the perl.
Here is the perl:
use CGI;
$max_num_files ||= 1;
$Data ||= $ENV{'DOCUMENT_ROOT'};
undef @bad_extensions if @good_extensions;
for(my $a = 1; $a <= $max_num_files; $a++) {
my $req = new CGI;
if($req->param("FILE$a")) {
my $file = $req->param("FILE$a");
#push(@name, $file); use this line for debug
my $filename = $file;
$filename =~ s/^.*(\\|\/)//;
$filename =~ s/ +/\_/g;
and yes the script only needed 1 param IN since I set max_num_files to 1 so name it FILE1 can do the job.
But then I tried input the link manually with .......upload.pl?FILE1=C:\Documents%20and%20Settin gs\example.jpg
to my suprise, its not working this way, so I think I narrow the problem to this:
Dose the "browser" button from html form ( encType=multipart/form-data method=post>File 1: <INPUT name=FILE1 type=file> <INPUT type=submit value=Upload!>)
output the same values if I has a file let say in C:\Documents and Settings\example.jpg, will FILE1 has value of C:\Documents%20and%20Settings\example.jpg when sending?
Thanks for your help and attention to this problem.
John
pichto
01-30-2003, 04:24 PM
So, it seems the loadVArs object doesn't work. If you have only one param to send to your perl script you can maybe use that :
loadVariables("upload.pl?FILE1="+filename, self);
And, in your perl script add a new variable, to be sent to flash, at the end to check if everything is ok (i.e. : success=true), then in flash you add something like that :
Create a loop sequence (over 3 or 4 frames)
Frame 1 :
loadVariables("upload.pl?FILE1="+filename, self);
Frame 4 :
if (success=="true"){
gotoAndPlay(5);
//go to next frame and do something...
}else{
gotoAndPlay(2);
//go back in the loop to check another time
}
Unfortunatly i can't tell you what to add in your perl because i don't know any word of perl programming...:(
P.S. : loadVariables is not crossdomain, so you have to use a relative path to your perl script.
JGizmo
02-04-2003, 09:50 AM
Thanks again pichto,
I think I have to use html form instead of using flash for uploading since I cant figue it out why it wont work with actionscript and other thing is when I try the browse button in MAC, (the browse button is in flash and by calling java script to act like a html browse button), it wont work but PC.
John
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.