Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-21-2011, 04:23 AM   #1
Registered User
Join Date: Sep 2007
Posts: 38
Default Create image in Flash, post to .NET (C#)

So I am trying to create an image in flash and post it to a .NET page so that it can be saved on the server. I am getting this error in the .NET page when I post: Invalid character in a Base-64 string

Any ideas? Thanks! I actually want to create a png but wanted to get it working with jpg first... (less moving parts)

ActionScript Code:
private function createJpg():void {             var image:BitmapData = new BitmapData(_png.width, _png.height);             image.draw(_png);             var enc:JPGEncoder = new JPGEncoder(85);             var bytes:ByteArray = enc.encode(image);             var base64:Base64Encoder = new Base64Encoder();             base64.encodeBytes(bytes);             var vars:URLVariables = new URLVariables();             vars.imageData = base64;                         var url:URLRequest = new URLRequest("localhost:1497/Services/FamineUploadImage.ashx");             url.data = vars;             url.method = URLRequestMethod.POST;                         var loader:URLLoader = new URLLoader();             loader.addEventListener(Event.COMPLETE, onSaveComplete);             loader.addEventListener(IOErrorEvent.IO_ERROR, onSaveError);             loader.load(url);         }

.NET Page:
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Services;
using StructureMap;
using WorldVision.Data.Services;

namespace WorldVision.Website.Services
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "tempuri")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class FamineUploadImage : IHttpHandler

        public void ProcessRequest(HttpContext context)
            var data = context.Request.Form["imageData"];

            // THIS IS WHERE IT ERRORS!
            byte[] bytes = Convert.FromBase64String(data);

            // Write the jpeg to disk
            string path = context.Server.MapPath("~/Save.jpg");
            File.WriteAllBytes(path, bytes);

            // Clear the response and send a Flash variable back to the URL Loader
            context.Response.ContentType = "text/plain";

        public bool IsReusable
                return false;
rook14 is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 08:28 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.