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:
Code:
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.Clear();
context.Response.ContentType = "text/plain";
context.Response.Write("ok=ok");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}