The RoLLing cOde

Rumor, crap and unoriginal | 谣言、扯淡、非原创

2007-11-12

File upload with URLRequest in AIR

A function to help upload without FileReference.upload() in AIR HTML/JS application.

Function Parameters:

void PrepareMultipartRequest(
URLRequest request, ByteArray file_bytes,
string field_name = "file", string native_path = "C:\FILE",
object data_before = {}, object data_after = {}
);

Sample JS Code:

var request = new air.URLRequest('http://example.com/upload.php');
var loader = new air.URLLoader();
var file = new air.File('C:\\TEST.TXT'); //use file.browseForOpen() on ur wish
var stream = new air.FileStream();
var buf = new air.ByteArray();
var extra = {
"id": "abcd"
};
stream.open(file, air.FileMode.READ);
stream.readBytes(buf);
MultipartRequest(request, buf, 'myfile', file.nativePath, extra);
loader.load(request);

Sample PHP Code:

$id = $_POST['id'];
move_uploaded_file($_FILES['myfile']['tmp_name'], '/opt/blahblah');

Download: multipart.js

Original code inspired from here.

Labels: ,

2007-11-11

"AIR crash"

The AIR(Adobe Integrated Runtime) 1.0b2 for win32 crashed on very simple js/html code.

Setting style.display of an iframe(or its container) element to none is dangerous, the workaround cound be setting style.visibility to hidden.

Get the crashing code here: AIRb2CrashSample.air.

It's even my first AIR program. :|

Labels: ,