Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:11:53+00:00 2026-05-28T17:11:53+00:00

I can’t seem to get this little AIR app I’m making to work right.

  • 0

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).

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 🙂 )

package
{

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 + "&name=name&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);
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:11:54+00:00Added an answer on May 28, 2026 at 5:11 pm

    there’s actually an example for AS3 on their site:

    package
    {
        import com.adobe.images.PNGEncoder;
        import flash.display.BitmapData;
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.SecurityErrorEvent;
        import flash.events.IOErrorEvent
        import flash.net.URLLoader;
        import flash.net.URLLoaderDataFormat
        import flash.net.URLRequest;
        import flash.net.URLRequestMethod;
        import flash.utils.ByteArray;
    
        public class ImgurExample
        {
            private var loader:URLLoader;
    
            private const API_KEY:String = "<api key>";
            private const UPLOAD_URL:String = "http://api.imgur.com/2/upload.xml";
    
            public function ImgurExample() {
    
                loader = new URLLoader();
                loader.dataFormat = URLLoaderDataFormat.VARIABLES;
                loader.addEventListener(Event.COMPLETE, onCookieSent);
                loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
                loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    
                // Create a bitmapdata instance of a movieclip on the stage.
                var mc:MovieClip;
                var b:BitmapData = new BitmapData(mc.width, mc.height, true);
                b.draw(mc);
                var png:ByteArray = PNGEncoder.encode(b);
    
                var vars:String = "?key=" + API_KEY + "&name=name&title=title";
                var request:URLRequest = new URLRequest(UPLOAD_URL + vars);
                request.contentType = "application/octet-stream";
                request.method = URLRequestMethod.POST;
                request.data = png; // set the data object of the request to your image.
    
                loader.load(request);
            }
            // privates
            private function onSend(e:Event):void {
                var res:XML = new XML(unescape(loader.data));
                trace(res);
            }
            private function onIOError(e:IOErrorEvent):void {
                trace("ioErrorHandler: " + e);
                // Handle error
            }
            private function onSecurityError(e:SecurityErrorEvent):void {
                trace("securityErrorHandler: " + e);
                // handle error
            }
    
        }
    }
    

    http://api.imgur.com/examples

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me why this doesn't work? <?php $lang = $_get[lang]; if (($lang
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can we change the default action of the edit selected row button? Here is
Can anyone explain to me why this program: for(float i = -1; i <
can someone explain what means this line, or provide with source where it is
Can someone please explain how this code is working for me? I don't understand
Can someone maybe tell me why this is not working? I have used echo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.