2012-06-19 79 views
0

我需要Flash才能將圖片上傳到我的網站。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"); 


} 
+0

是否有不使用調用FileReference.upload(URL)的原因是什麼? –

回答

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 
}