Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to call an aspx that accepts parameters through HTTP POST and returns an image, and then display the image in my html?

Reply
Thread Tools

How to call an aspx that accepts parameters through HTTP POST and returns an image, and then display the image in my html?

 
 
computer_guy
Guest
Posts: n/a
 
      07-20-2007
Hi Everyone,

I run into a problem. I am trying to write an aspx that can
dynamically generate an image based on some input parameters.

Things are very simple if the size of the parameters is small and I
can put them on the URL and pass them in as HTTP GET. In my image
generation script I just need to read the parameters and then pump out
the right MIME type and the right image byte stream. It is also very
easy to use:

<img source="image_gen.aspx?p1=...."> will do the trick.


However, it looks like I need to pass in more parameters than HTTP GET
can support. I am thinking about HTTP POST. I think I can still write
the image generation script the same way, but the question now is how
to call the script and display the image in my html.


<img source="image_gen.aspx" and HTTP POST to this URL> How?

Does anyone know?

Thanks,
computer_guy

 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      07-20-2007
You could use a control that inherits from IHttpHandler like this:

<%@ WebHandler Language="C#"
Class="AspNet.StarterKits.Classifieds.Web.PhotoDis play" %>

using System;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web;
using AspNet.StarterKits.Classifieds.BusinessLogicLayer;


namespace Mynamespace
{
public class PhotoDisplay : IHttpHandler
{
public const string QueryStringFullSize = "full";
public const string QueryStringMediumLarge = "large";
public const string QueryStringMediumSize = "medium";
public const string QueryStringMediumSmall = "small";
public void ProcessRequest(HttpContext context)
{

HttpResponse Response = context.Response;
HttpRequest Request = context.Request;
Image myThumbnail = new Bitmap(1,1);

//string url2 = Path.Combine(@"c:\attachments", "110.jpg");
if (Request.QueryString["photoid"] != null)
{
// Retrieve the path to the file.
string url2 =
GetPicturePath(Request.QueryString["photoid"],context);
if (url2.Length > 0)
{

Image.GetThumbnailImageAbort myCallback = new
Image.GetThumbnailImageAbort(ThumbnailCallback);
Image fullImg = Image.FromFile(url2);
if (Request.QueryString["size"] ==
QueryStringMediumSmall)
myThumbnail = fullImg.GetThumbnailImage(100, 100,
myCallback, IntPtr.Zero);
if (Request.QueryString["size"] == QueryStringMediumSize)
myThumbnail = fullImg.GetThumbnailImage(200, 200,
myCallback, IntPtr.Zero);
if (Request.QueryString["size"] == QueryStringMediumLarge)
myThumbnail = fullImg.GetThumbnailImage(300, 300,
myCallback, IntPtr.Zero);
if (Request.QueryString["size"] == QueryStringFullSize)
myThumbnail = fullImg;

// make a memory stream to work with the image bytes
MemoryStream imageStream = new MemoryStream();

// put the image into the memory stream
myThumbnail.Save(imageStream, ImageFormat.Jpeg);

// make byte array the same size as the image
byte[] imageContent = new Byte[imageStream.Length];

// rewind the memory stream
imageStream.Position = 0;

// load the byte array with the image
imageStream.Read(imageContent, 0,
(int)imageStream.Length);

//byte[] allBytes = File.ReadAllBytes(url2);
Response.ContentType = "image/jpeg";
Response.Cache.SetCacheability(HttpCacheability.Pu blic);
Response.BufferOutput = false;
Response.OutputStream.Write(imageContent, 0,
imageContent.Length);
}

}
//e.Graphics.DrawImage(myThumbnail, 150, 75);

}
public bool ThumbnailCallback()
{
return false;
}

public bool IsReusable
{
get
{
return true;
}
}

}
}

Then call the control like this:
<img id="ss_img" src="PhotoDisplay.ashx?photoid=KeyForImage&amp;siz e=large"
alt="My Image" width="230" />

Just for the photoid be sure and pass something in that indicates what photo
you want. If you are generating the image at runtime - perhaps you can use
more than one parameter that can indicate Width, Height, content, etc...

-Brian

"computer_guy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi Everyone,
>
> I run into a problem. I am trying to write an aspx that can
> dynamically generate an image based on some input parameters.
>
> Things are very simple if the size of the parameters is small and I
> can put them on the URL and pass them in as HTTP GET. In my image
> generation script I just need to read the parameters and then pump out
> the right MIME type and the right image byte stream. It is also very
> easy to use:
>
> <img source="image_gen.aspx?p1=...."> will do the trick.
>
>
> However, it looks like I need to pass in more parameters than HTTP GET
> can support. I am thinking about HTTP POST. I think I can still write
> the image generation script the same way, but the question now is how
> to call the script and display the image in my html.
>
>
> <img source="image_gen.aspx" and HTTP POST to this URL> How?
>
> Does anyone know?
>
> Thanks,
> computer_guy
>


 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      07-20-2007
FYI - the class file should have an ".ashx" extension.

"computer_guy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi Everyone,
>
> I run into a problem. I am trying to write an aspx that can
> dynamically generate an image based on some input parameters.
>
> Things are very simple if the size of the parameters is small and I
> can put them on the URL and pass them in as HTTP GET. In my image
> generation script I just need to read the parameters and then pump out
> the right MIME type and the right image byte stream. It is also very
> easy to use:
>
> <img source="image_gen.aspx?p1=...."> will do the trick.
>
>
> However, it looks like I need to pass in more parameters than HTTP GET
> can support. I am thinking about HTTP POST. I think I can still write
> the image generation script the same way, but the question now is how
> to call the script and display the image in my html.
>
>
> <img source="image_gen.aspx" and HTTP POST to this URL> How?
>
> Does anyone know?
>
> Thanks,
> computer_guy
>


 
Reply With Quote
 
computer_guy
Guest
Posts: n/a
 
      07-20-2007
Thanks a lot for your help.

The problem is that the url is too short to specify all the
parameters. It is more like the following:

<img id="ss_img" src="PhotoDisplay.ashx?data=<Large Block of Data Here
(~ 32 KB) > />

The reason I am doing this is because the data used to parameterize
the image is generated on the fly. Eventually I want something like
this:

Dynamic HTML Page
-------------------------------

1. Complicated algorithm to generate data and store it in memory

2. Inline Image to visualize generated data in graphic form.
(This is something I am hoping I can generate on the fly with another
script.)

3. HTML table to visualize generated data in tabluar form.

------------------End of HTML Page------------------

The problem here is that I don't want to call or write the algorithm
(1 above) twice when displaying it in graphic and tabular form.

So if I want to pass a large block of data to PhotoDisplay.ashx below
through HTTP POST, can I do it?

<img id="ss_img" src="PhotoDisplay.ashx?data=<Large Block of Data Here
(~ 32 KB) > />

Thanks a lot,
computer_guy

On Jul 19, 9:38 pm, "Brian" <(E-Mail Removed)> wrote:
> FYI - the class file should have an ".ashx" extension.
>
> "computer_guy" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) ups.com...
>
>
>
> > Hi Everyone,

>
> > I run into a problem. I am trying to write an aspx that can
> > dynamically generate an image based on some input parameters.

>
> > Things are very simple if the size of the parameters is small and I
> > can put them on the URL and pass them in as HTTP GET. In my image
> > generation script I just need to read the parameters and then pump out
> > the right MIME type and the right image byte stream. It is also very
> > easy to use:

>
> > <img source="image_gen.aspx?p1=...."> will do the trick.

>
> > However, it looks like I need to pass in more parameters than HTTP GET
> > can support. I am thinking about HTTP POST. I think I can still write
> > the image generation script the same way, but the question now is how
> > to call the script and display the image in my html.

>
> > <img source="image_gen.aspx" and HTTP POST to this URL> How?

>
> > Does anyone know?

>
> > Thanks,
> > computer_guy- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Programmatic HTTP Post returns Empty Form fields on ASPX Server Side ERobishaw ASP .Net 1 03-22-2008 09:59 PM
Syntax for call from aspx page to .cs file then to different aspx page MadHatter51 ASP .Net 1 05-17-2006 10:43 AM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM



Advertisments