473,790 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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_g en.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_g en.aspx" and HTTP POST to this URLHow?

Does anyone know?

Thanks,
computer_guy

Jul 20 '07 #1
3 3612
You could use a control that inherits from IHttpHandler like this:

<%@ WebHandler Language="C#"
Class="AspNet.S tarterKits.Clas sifieds.Web.Pho toDisplay" %>

using System;
using System.Configur ation;
using System.Data;
using System.Drawing;
using System.Drawing. Imaging;
using System.IO;
using System.Web;
using AspNet.StarterK its.Classifieds .BusinessLogicL ayer;
namespace Mynamespace
{
public class PhotoDisplay : IHttpHandler
{
public const string QueryStringFull Size = "full";
public const string QueryStringMedi umLarge = "large";
public const string QueryStringMedi umSize = "medium";
public const string QueryStringMedi umSmall = "small";
public void ProcessRequest( HttpContext context)
{

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

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

Image.GetThumbn ailImageAbort myCallback = new
Image.GetThumbn ailImageAbort(T humbnailCallbac k);
Image fullImg = Image.FromFile( url2);
if (Request.QueryS tring["size"] ==
QueryStringMedi umSmall)
myThumbnail = fullImg.GetThum bnailImage(100, 100,
myCallback, IntPtr.Zero);
if (Request.QueryS tring["size"] == QueryStringMedi umSize)
myThumbnail = fullImg.GetThum bnailImage(200, 200,
myCallback, IntPtr.Zero);
if (Request.QueryS tring["size"] == QueryStringMedi umLarge)
myThumbnail = fullImg.GetThum bnailImage(300, 300,
myCallback, IntPtr.Zero);
if (Request.QueryS tring["size"] == QueryStringFull Size)
myThumbnail = fullImg;

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

// put the image into the memory stream
myThumbnail.Sav e(imageStream, ImageFormat.Jpe g);

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

// rewind the memory stream
imageStream.Pos ition = 0;

// load the byte array with the image
imageStream.Rea d(imageContent, 0,
(int)imageStrea m.Length);

//byte[] allBytes = File.ReadAllByt es(url2);
Response.Conten tType = "image/jpeg";
Response.Cache. SetCacheability (HttpCacheabili ty.Public);
Response.Buffer Output = false;
Response.Output Stream.Write(im ageContent, 0,
imageContent.Le ngth);
}

}
//e.Graphics.Draw Image(myThumbna il, 150, 75);

}
public bool ThumbnailCallba ck()
{
return false;
}

public bool IsReusable
{
get
{
return true;
}
}

}
}

Then call the control like this:
<img id="ss_img" src="PhotoDispl ay.ashx?photoid =KeyForImage&am p;size=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_g uy" <zy*******@gmai l.comwrote in message
news:11******** *************@r 34g2000hsd.goog legroups.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_g en.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_g en.aspx" and HTTP POST to this URLHow?

Does anyone know?

Thanks,
computer_guy
Jul 20 '07 #2
FYI - the class file should have an ".ashx" extension.

"computer_g uy" <zy*******@gmai l.comwrote in message
news:11******** *************@r 34g2000hsd.goog legroups.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_g en.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_g en.aspx" and HTTP POST to this URLHow?

Does anyone know?

Thanks,
computer_guy
Jul 20 '07 #3
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="PhotoDispl ay.ashx?data=<L arge 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.as hx below
through HTTP POST, can I do it?

<img id="ss_img" src="PhotoDispl ay.ashx?data=<L arge Block of Data Here
(~ 32 KB) />

Thanks a lot,
computer_guy

On Jul 19, 9:38 pm, "Brian" <brianpatter... @ishcm.comwrote :
FYI - the class file should have an ".ashx" extension.

"computer_g uy" <zyzhu2...@gmai l.comwrote in message

news:11******** *************@r 34g2000hsd.goog legroups.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_g en.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_g en.aspx" and HTTP POST to this URLHow?
Does anyone know?
Thanks,
computer_guy- Hide quoted text -

- Show quoted text -

Jul 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6706
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
7
4971
by: Danny | last post by:
Newbie here Thanks for the help with this command: print "Status: 204 No Content\n\n"; which returns nothing in a perl script. This is great because I just want my perl script to increment a counter and put result in a text file which it does fine how. But now how do I call this from an .html? I used to call it like this <img src="path to cgi script"> this increments the counter but there is a little box where an actual image should...
8
2595
by: Peter Nolan | last post by:
Hi All, I have written some software that performs ETL processing to load data warehouses. Each program accepts a set of parameters and returns 0 or 1 to the win/unix shell to indicate success or failure. Currently it is run as a set of commands that calls each program and then returns the return code and stops if the program has failed. I'm interested in enhancing the product by being able to call these programs from within another C++...
1
2106
by: Adam | last post by:
I am having difficulty retrieving images from a SQL database. Here is the code I use to UPLOAD the image to the database: <form id="Form1" method="post" enctype="multipart/form-data" runat="server"> <INPUT id="UploadedImageFile" runat=server type="file" size="86"> </form>
10
2351
by: Adis | last post by:
Asp.Net Visual Studio 2003 SQL Server. Hi, Obtaining Data Based Upon Multiple Selections From a ListBox... I have database in Sqlserver and ListBox (Multiple Selection Mode) in my Visual Studio Webform. I wish obtain various records from My_Store_Procedure
6
5517
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp; DataBinder.Eval(Container.DataItem,"StoreEmail") &amp; "&amp;Subject=" &amp; DataBinder.Eval(Container.DataItem,"ProductName") ....
0
1993
by: guddi1 | last post by:
Hi, I am looking to figure out how to display parameters of a post request. I am working in visual C++ environment. I have a program that tracks and outputs URL activity. For instance, when I log in to my yahoo email account, the program outputs the following headers: (Request for https://login.yahoo.com/config/login?) POST /config/login? HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash,...
4
3877
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
11
2970
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page, having hyperlinks to the corresponding full size images. Can anybody point me to locations in MSDN or elsewhere giving the references to attach, the commands & objects for creating or opening the pages and possibly available classes? I have done...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.