Note that there are some explanatory texts on larger screens.

plurals
  1. POAIR: how to use FileReference.upload() with POST-based web services (AS3)
    primarykey
    data
    text
    <p>I can't seem to get this little AIR app I'm making to work right. There is a single button on the stage, and when the user presses it they are presented with a file browser (FileReference.browse() function). When they select an image file, I want the image to be uploaded to the site imgur.com (http://www.api.imgur.com for those interested).</p> <p>I'm getting a response from imgur, so I know my app is connecting, but it's returning an error, "No image data was sent to the upload API". Any help is greatly appreciated! (Also I do have an API key, just removed it from this post for obvious reasons :) )</p> <p>package {</p> <pre><code>import flash.display.MovieClip; import flash.events.*; import flash.net.*; import flash.utils.ByteArray; public class Document extends MovieClip { //file browser var var myFileReference:FileReference = new FileReference(); //file loader var private var loader:URLLoader; //string constants private const API_KEY:String = "******REMOVED*******"; private const UPLOAD_URL:String = "http://api.imgur.com/2/upload.xml"; public function Document() { // constructor code browse_btn.addEventListener(MouseEvent.CLICK, browse); } function browse(e:MouseEvent) { var imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.gif;*.png"); myFileReference.browse([imagesFilter]); myFileReference.addEventListener(Event.SELECT, selectHandler); myFileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, responseHandler); } function selectHandler(e:Event):void { var vars:String = "?key=" + API_KEY + "&amp;name=name&amp;title=title"; var params:URLVariables = new URLVariables(); params.date = new Date(); var request:URLRequest = new URLRequest(UPLOAD_URL + vars); //request.contentType = "application/octet-stream"; request.contentType = "multipart/form-data"; request.method = URLRequestMethod.POST; request.data = params; myFileReference.upload(request); try { myFileReference.upload(request); } catch (error:Error) { trace("Unable to upload file."); } } function responseHandler(e:DataEvent):void { trace("responseHandler() initaialized"); var res:XML = XML(e.data); trace(res); } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload