Groups | Blog | Home
all groups > flash data integration > march 2006 >

flash data integration : Re: uploading file with flash 8 and ASP


rizalfir
3/8/2006 6:18:44 PM
Well,
the Flash upload is producing different POST data. Yyou will have to create
your own binary parser.
Upload.asp simply won't work without modification.

The problem with Flash POST data is it doesn't have "--" terminator in each
transaction.
So, you need to modfify that case in upload.asp

I've made an ASP class to do this Flash upload thing, perhaps you can learn
from the live example:

http://www.masrizal.com/index.cfm?fuseaction=idea.download_detail&ProductID=asp_
flashupload
ck1mark
3/9/2006 3:53:25 AM
asp.net ok? hey if i use this script do i need asp.net hosting?

"Script from Flash 8: Training From the source" get the book its good
<% @Page Language="C#" %>
<% @Import Namespace="System.Drawing" %>
<% @Import Namespace="System.Drawing.Imaging" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Text" %>

<script language="c#" runat="server">

private string _imageSize = "1";
private string _quick = "false";
private string _action = null;

private static string IMAGE_HANDLE = "ImageHandle";

private void Page_Load(Object sender, EventArgs e) {

_action = Request;

if(_action == "post") {

HttpFileCollection files = Request.Files;

// Do we have anything to work with?
if(files.Count > 0) {

/*if(files.ContentType=="image/gif" ||
files.ContentType=="image/jpg" ||
files.ContentType=="image/jpeg" ||
files.ContentType=="image/pjpeg" ||
files.ContentType=="image/bmp")
{*/

try {
Session = "<xmp>" + ConvertImage(files.InputStream, _imageSize, _quick )
+ "</xmp>";
} catch(Exception ex) {
Session = "Error occured with the image upload! Message: " + ex.Message;
}
/*}
else
{
Session = "Please upload a image of type gif or jpg!" +
"<br/><br/>You uploaded:" +
files.ContentType + "<br/>";
}*/

} else {
Session = "You didn't upload anything!";
}

}

}

public static string ConvertImage(Stream stream, string ImageSize, string
Quick)
{
StringBuilder _asciiart = new StringBuilder();


System.Drawing.Image _img = System.Drawing.Image.FromStream(stream);
Bitmap _image = new Bitmap(_img, new Size(_img.Width, _img.Height));
_img.Dispose();


Rectangle bounds = new Rectangle(0, 0, _image.Width, _image.Height);


ColorMatrix _matrix = new ColorMatrix();

_matrix = 1/3f;
_matrix = 1/3f;
_matrix = 1/3f;
_matrix = 1/3f;
_matrix = 1/3f;
_matrix = 1/3f;
_matrix = 1/3f;
_matrix = 1/3f;
_matrix = 1/3f;

ImageAttributes _attributes = new ImageAttributes();
_attributes.SetColorMatrix(_matrix);


Graphics gphGrey = Graphics.FromImage(_image);
gphGrey.DrawImage(_image, bounds, 0, 0, _image.Width, _image.Height,
GraphicsUnit.Pixel, _attributes);

gphGrey.Dispose();



int _pixwidth;

switch (ImageSize)
{
case "1":
{
_pixwidth = 1;
break;
}
case "2":
{
_pixwidth = 2;
break;
}
case "4":
{
_pixwidth = 6;
break;
}
case "5":
{
_pixwidth = 8;
break;
}
default:
{
_pixwidth = 3;
break;
}
}
int _pixhight = _pixwidth * 2;
int _pixseg = _pixwidth * _pixhight;

for(int h=0; h < _image.Height / _pixhight; h++)
{
// segment hight
int _startY = (h * _pixhight);
// segment width
for(int w = 0; w < _image.Width / _pixwidth; w++)
{
int _startX = (w *_pixwidth);
int _allBrightness = 0;

if(Quick == "True")
{
// each pix of this segment
for(int y = 0; y < _pixwidth; y++)
{
try
{
Color _c = _image.GetPixel(_startX,y+_startY);
int _b = (int)(_c.GetBrightness() * 100);
_allBrightness = _allBrightness + _b;
}
catch
{
_allBrightness = (_allBrightness + 50);
}
}
}
else
{
// each pix of this segment
for(int y = 0; y < _pixwidth; y++)
{
for(int x = 0; x < _pixhight; x++)
{
int _cY = y + _startY;
int _cX = x + _startX;
try
{
Color _c = _image.GetPixel(_cX, _cY);
int _b = (int)(_c.GetBrightness() * 100);
_allBrightness = _allBrightness + _b;
}
catch
{
_allBrightness = (_allBrightness + 50);
}
}
}
}

int _sb = (_allBrightness / _pixseg);

if (_sb < 10 )
{
_asciiart.Append("#");
}
else if (_sb < 17 )
{
_asciiart.Append("@");
}
else if (_sb < 24)
{
_asciiart.Append("&");
}
else if (_sb < 31)
{
_asciiart.Append("$");
}
else if (_sb < 38)
{
_asciiart.Append("%");
}
else if (_sb < 45)
{
_asciiart.Append("|");
}
else if (_sb < 52)
{
_asciiart.Append("!");
}
else if (_sb < 59)
{
_asciiart.Append(";");
}
else if (_sb < 66)
{
_asciiart.Append(":");
}
else if (_sb < 73)
{
_asciiart.Append("'");
}
else if (_sb < 80)
{
_asciiart.Append("`");
}
else if (_sb < 87)
{
_asciiart.Append(".");
}
else
{
_asciiart.Append(" ");
}
}
_asciiart.Append("\n");
}

//clean up
_image.Dispose();

return _asciiart.ToString();

}


</script>

<%
if(_action == null) {
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Upload Test Form</title>
</head>

<body>

<form action="FileUpload.aspx?action=post" method="post"
enctype="multipart/form-data">
<input type="file" name="fileUpload" size="20">
<input type="submit" value=" Go ">
</form>

</body>
</html>

<%
} else if(_action == "view") {
%>
<%=Session%>
<%
}
%>


AddThis Social Bookmark Button