Service response file SRF directly transmits the code snippet of the image stream to the browser

Source: Internet
Author: User

Question: The service response file SRF directly transmits the code snippet of the image stream to the client browser

 

Cheungmine


Question: How to directly write image data to a stream from the Web server and display it in the client browser

Why: efficiency and security. Do not generate temporary files. Full memory operation.

 

I used vs2005 to create an ATL server project and merge isapis. Others are as usual. Project name: refreshimg. Automatically create virtual directories with the same name and deploy them automatically.

 

1) rewrite the following code in the refreshimg. h file:

 

// The following is an example of how to use the replacement tag for a mold (stencer) processor.
Http_code onhello (void)
{
// M_httpresponse <"Hello world! ";

Char Buf [4096];
Size_t cbread;
DWORD dwwritten;

M_httpresponse.clearcontent ();
M_httpresponse.setcontenttype ("image/JPEG ");

 

// The image file below must exist
File * fp = fopen ("C: // inetpub // wwwroot // refreshimg // obm_skq.jpg", "Rb ");

While (cbread = fread (BUF, 1, 4096, FP)> 0 ){
If (s_ OK! = M_httpresponse.writestream (BUF, cbread, & dwwritten) | cbread! = Dwwritten ){
Fclose (FP );
Return http_fail;
}
}

Return http_success;
}

 

2) rewrite refreshimg. SRF:

<HTML>
{Handler refreshimg. dll/default }}
<Head>
</Head>
<Body>

</Body>
</Html>

 

3) regenerate all solutions, and then use IE or FF to open

 

Http: // localhost/refreshimg. SRF

 

You can see the image.

 

You can also write a new refresh.htm webpage, as shown below:

<HTML>
<Head>
<Title> cheungmine </title>
</Head>
<Body>

</Body>
</Html>

 

Put refresh.htm in the same directory as refreshimg. SRF.

 

In this case, you can view the refresh.htm image:

>

 

. Net. But this article has nothing to do with. net.

 

 

 

 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.