all groups > flash actionscript > august 2007 >
You're in the

flash actionscript

group:

Problems with FileUpload


Problems with FileUpload ticktak
8/5/2007 3:09:23 AM
flash actionscript:
HI,
I am uploading files to a server using the FileReference Class. I works well
on my localhost. When I go online it fails with Opera, Safari and Firefox on
mac. On a Windows PC it only works with Internet Explorer.

Has anyone else experienced this? I read several posts online with similar
issues, but no way to work this around.

Why is this happening? Is this a bug? or an issue of my server?

Thanks for your insights

Re: Problems with FileUpload ticktak
8/5/2007 3:11:54 AM
BTW, in every browser where it fails the error I get is this:

Re: Problems with FileUpload kglad
8/5/2007 4:24:34 AM
Re: Problems with FileUpload ticktak
8/5/2007 4:50:27 AM
Thanks kglad,
I fear the problem is more than that though. I just tried exactly the same
files on a different server and they worked on both Safari, and Firefox on a
Mac.

The example I'm trying is very simple: a single file is selected and then
transfered to a folder. There's no file manipulation or whatsoever.

I read in other forums of users reporting problems with Firefox on macs while
uploading files. Others didn't notice that problem. It makes me think it is a
problem related to the server and the headers Flash sends.

I noticed for instance that when uploading an image file, flash sends this:

type = application/octet-stream

as opposed to:

type = image/jpg, which prevents some image processing scripts from dealing
with the file.

I've spent many days dealing with this and it's already a very frustrating
thing. Not to belittle flash, but a simple file upload through an html form
takes 2 seconds, and it's 100% warranted to work. Things as simple as this
should not be such an endeavor. We are not sure what to do now about this
project.
Re: Problems with FileUpload kglad
8/5/2007 5:45:52 PM
Re: Problems with FileUpload ticktak
8/5/2007 8:01:22 PM
Thanks for taking a look at this code.
As I mentioned it earlier I have mix results with it:
It works here:
-My localhost testing from within flash, and from safari, and firefox.
-Server A (a friend's): from any windows PC and Mac browser
-Server B (where it should be finally hosted): Only works from windows PC
browsers. Whenever I tried from a mac browser I get this error:
Error #2038: File I/O Error. URL: url of php script.

Earlier I made the php script that I'm addressing print a confirmation
variable whenever it is called. In the situations the upload fails it seems
that flash cannot even address it (!) since the script doesn't even print that
variable.
So here's the code:




// FLASH MOVIE: IT IS A SINGLE BUTTON MOVIE TO PROMPT THE UPLOAD,
// AND A TEXT FIELD SHOWING ANY ERROR OR COMPLETED MESSAGES.
//
import flash.events.*;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;


Security.loadPolicyFile("http://www.mauricioarango.net/LAB/SaoPaulo/policy.xml")
;

var totalTransfers:int = 0;
var fr:FileReference;
single.buttonMode = true;

single.addEventListener (MouseEvent.CLICK, uploadFiles);

function uploadFiles (e:MouseEvent):void {
fr = new FileReference;
fr.browse ();
fr.addEventListener (Event.SELECT, selectHandler);
fr.addEventListener (Event.OPEN, openHandler);
fr.addEventListener (ProgressEvent.PROGRESS, progressHandler);
fr.addEventListener (Event.COMPLETE, completeHandler);
fr.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);
}

function selectHandler (e:Event):void {
var request:URLRequest = new URLRequest();
//request.url = "http://www.mauricioarango.net/LAB/SaoPaulo/test.php";
request.url = "http://localhost/~mauro/SaoPaulo/test.php";
request.method = URLRequestMethod.POST;
//
fr.upload (request);
}

function openHandler (e:Event):void {
//
}

function progressHandler (e:Event):void {
//
}

function completeHandler (e:Event):void {
//
totalTransfers ++;
errorsReturn.appendText('\n FILE TRANSFERED'+ ' ' +totalTransfers );
}
function ioErrorHandler (event:IOErrorEvent):void {
//trace ("ioErrorHandler: " + event);
trace (event.currentTarget);
trace (event.target);
trace (event.text);
errorsReturn.text = event.text;
}

///////////////////////////////////////
///////////////////////////////////////
// PHP FILE: ALL IT DOES IS TO PUT THE UPLOADED FILE IN THE DESTINATION
DIRECTORY
<?PHP
$target_path = "uploads/";
// Add the original filename to our target path.
// Result is "uploads/filename.extension"
$target_path = $target_path . basename( $_FILES['Filedata']['name']);
$_FILES['Filedata']['tmp_name'];
move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path);
echo '1';
?>
Re: Problems with FileUpload ticktak
8/5/2007 10:47:23 PM
In case this is of any use:
these are the headers from the server where it fails and the server where it
succeeds:

UNSUCCESSFUL ATTEMPT:


UNSUCCESSFUL ATTEMPT

RESPONSE:
HTTP/1.1 405 Method Not Allowed

Date: Sun, 05 Aug 2007 22:28:48 GMT

Server: Apache/1.3.34 (Unix)

Allow: GET, HEAD, OPTIONS, TRACE

Connection: close

Transfer-Encoding: chunked

Content-Type: text/html; charset=iso-8859-1

=========================================

AND These are the ones from a successful response:


RESPONSE

HTTP/1.1 200 OK

Date: Sun, 05 Aug 2007 22:25:14 GMT

Server: Apache/1.3.34 (Unix) mod_fastcgi/2.4.2 mod_perl/1.26

X-Powered-By: PHP/5.2.0

Vary: NFInfo

Content-Type: text/html

X-Cache: MISS from www.mauricioarango.net

Transfer-Encoding: chunked
AddThis Social Bookmark Button