Flash将图像上传到网页

时间:2012-06-19 08:20:39

标签: flash rest post actionscript

我需要让Flash将图片上传到我的网站。

该网站运行正常,我可以上传一个简单的HTML工作。

但是如何让Flash将图像发布到网站?

这是当前的ActionScript

public function encodeAndSave()
{
var bmd : BitmapData = new BitmapData( 300, 300, true, 0xFFFFFFFF );


// draw the bitmapData from the captureContainer to the bitmapData object;
bmd.draw( index.avatarMC, new Matrix(), null, null, null, true );


// create a new JPEG byte array with the adobe JPEGEncoder Class;
var byteArray : ByteArray = new JPGEncoder( 90 ).encode( bmd );


var date:Date = new Date();
var req:URLRequest = new URLRequest("http://bt.ind-igo.co.uk/test/SaveImage");


var params:URLVariables = new URLVariables();
params.file= Base64.encode(byteArray);


params.name = "MyImage.jpg";
req.method = URLRequestMethod.POST;
req.data = params;
var ldr:URLLoader = new URLLoader(req);


ldr.addEventListener(Event.COMPLETE, complete);


ldr.load(req);


function complete(e:Event):void
{
navigateToURL(new URLRequest("?" + Math.random()), "_self");


}

1 个答案:

答案 0 :(得分:0)

下载我的小FileSaver类,在它的帮助下,您可以保存在服务器上,也可以在本地保存! http://www.myflashlab.com/2010/02/21/filesaver-data-transfer/

import com.doitflash.tools.fileSaver.FileSaver;
import com.doitflash.tools.fileSaver.FileSaverConst;
import com.doitflash.events.FileSaverEvent;

// if we're saving to server
var _fileSaver:FileSaver = new FileSaver();
_fileSaver.method = FileSaverConst.SERVER;

// by default the encryption is turned off. if you are turning it on,
// make sure to put a key for your encryption which is not longer than 8 characters.
// to deal with encrypted data on your server side script, refer to http://code.google.com    /p/as3crypto/
//_fileSaver.encrypt(true, "TESTTEST");
_fileSaver.encrypt(false);
_fileSaver.gateway = "phpProcessor.php";

// save all parameters that you want to send out in an object like below.
_fileSaver.vars = {var1:"value1",var2:"value2"};

// you may also wish to add a listener to receive the server script respond!
_fileSaver.addEventListener(FileSaverEvent.RESPOND, onRespond);

// call the save method and pass the file byteArray to it along with its name like below.
_fileSaver.save(_byte, "filename", ".gif");

function onRespond(e:FileSaverEvent):void
{
    trace(e.paramURLVars) // paramURLVars is of type URLVariables
    trace(e.paramOBJVars) // paramOBJVars is of type Object

    // OR

    trace(_fileSaver.theRespond);// theRespond is of type URLVariables
    trace(_fileSaver.theRespondObject);// theRespondObject is of type Object
}