Giter VIP home page Giter VIP logo

multipart.as's Introduction

#Multipart.as

A multipart form data request generator

##Demo :

http://labs.positronic.fr/flash/multipart/

The JPEGEncoder used in this demo can be found here: http://www.bytearray.org/wp-content/projects/fastjpeg/JPEGEncoder.as

##Restrictions :

In Flash Player 10 and later, if you use a multipart Content-Type (for example "multipart/form-data") that contains an upload (indicated by a "filename" parameter in a "content-disposition" header within the POST body), the POST operation is subject to the security rules applied to uploads:

  • The POST operation must be performed in response to a user-initiated action, such as a mouse click or key press. [adobe outdated documentation ?]

  • If the POST operation is cross-domain (the POST target is not on the same server as the SWF file that is sending the POST request), the target server must provide a URL policy file that permits cross-domain access.

Source : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html

How to use it

Create a new Multipart object giving it the url you're asking for. The method will be automatically set at POST.

Then you can use the following methods agains your object:

  • addField(string fieldName, string value)
  • addFile(string fieldName, ByteArray file, string mimeType, string fileName)

Then you can retrieve the request at yourObject.request and load it with the native urlloader of actionscript.

Extracted from the Demo, here is a basic example:

// Instanciate Multipart with url
var form:Multipart = new Multipart(url);

// Add fields
form.addField("field1", "hello");
form.addField("field2", "world");

// Add files
form.addFile("file1", text, "text/plain", "test.txt");
form.addFile("file2", image, "image/jpeg", "test.jpg");

// Load request
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
try {
	loader.load(form.request);
} catch (error: Error) {
	textField.text = "Unable to load request : "+error.message;
}

multipart.as's People

Contributors

jimojon avatar normanzb avatar zlumer avatar nek- avatar

Watchers

James Cloos avatar 橙色下午茶 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.