I'm stumped... I have an app in which users can save screenshots. The app draws to a bitmap, uploads the data, the server creates the file, and the user is then prompted to download the file.
It works great in all browser/OS combos with the exception of FF2/XP. The file is uploaded, but the user doesn't receive the download prompt. What gives?
// EDIT: Turns out the security error is thrown at the start of the upload attempt.
Woo-hoo! It's not working in IE7/Vista or FF2/Vista either!
your saving a jpg to the server, is that were the prob is or somewhere else?
Threw in a debug trace. It looks as though it's a security issue - Error #2170 - that occurs during file upload.
Getting closer, but still stumped.
Here's what I've tried, all of which happen to coincide with where I've failed:
Security.allowDomain(DOMAIN);
^ probably moot given that the image data is uploaded via URLLoader, which doesn't take a LoaderContext as the second param for load() as Loader does.
Enjoy:
// post to server
private function postToServer(byteArray:ByteArray){
// create a random filename
_strFileName = "littleguy" + Math.floor(Math.random()*1000000) + ".jpg";
// optional name/value pairs
var parameters:Object = new Object(); // optional generic object containing name value pairs to accompany the post
// set up the security handling
Security.allowDomain(DOMAIN);
// set up the request & headers for the image upload;
var urlRequest : URLRequest = new URLRequest();
urlRequest.url = UPLOADPATH + UPLOADSCRIPT;
urlRequest.contentType = 'multipart/form-data; boundary=' + UploadPostHelper.getBoundary();
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = UploadPostHelper.getPostData( _strFileName, byteArray );
urlRequest.requestHeaders.push( new URLRequestHeader( 'Cache-Control', 'no-cache' ) );
// create the image loader & send the image to the server;
var urlLoader : URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
urlLoader.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
urlLoader.load( urlRequest);
}
A little correction for clarification: the data is not being uploaded. The security error is thrown at the start of the upload attempt.
All righty. Moving the php script to the same server as the swf seems to have taken care of the security error... on most machines. The two I was most concerned about - IE6/XP and FF2/XP - are now squared away. It still throws the error on FF2/[some unknown and old version of Mac OS], but hey... it's progress.
Here's an idea which I untidied prior to posting
_jpgUrlReq=new URLRequest(_sendImagePath+'?id='+id+'&cashKill='+(new Date()).getTime());
_jpgUrlReq.requestHeaders.push(new URLRequestHeader("Content-type","application/octet-stream"));
_jpgUrlReq.method=URLRequestMethod.POST;
_jpgUrlReq.data=(new JPGEncoder(COMPRESS)).encode((new BitmapData(_w,_h).draw(_img));
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.INIT, onComplete );
l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioError );
l.load(_jpgUrlReq);
the php needs to return a dummy image, as far as I know it works cross browser/platform but is rather dirty in its use of loader.