Demonstrates how to convert, store, and retrieve images. Allows the user to upload images that the server will attempt to convert to PNG format. If successful, the PNG format data is added to a database. Images in the database can be downloaded using a URL that contains the ID of the image as a parameter in the query string.
Extra Installation Steps
- Create a SQL server database and run the ShowImage.sql SQL script to create the necessary tables and stored procedures.
- Before building and deploying the application, double-click ShowImage.udl and configure the data link properties to point to the database you just set up.
If the database connection uses Windows authentication, make sure that the IUSR_Machine account has read-write access to the database. See ATL Server Security for information about the accounts used by a typical ATL Server application running in IIS.
If the database connection uses SQL authentication, make sure that the security information is persisted.
- After building and deploying the application, change the NTFS security settings on the UDL file that was deployed to the same location as ShowImage.dll to allow read access by the IUSR_Machine account.
Use a browser to view ShowImage.srf and use the form linked to from that page to send some image files to the server. The server will attempt to convert the files to PNG format and add the image data to the database. The response will indicate which files were received by the server, which files were images, which could be converted to PNG format, and which of those could be added to the database. Any images added to the database will be displayed as part of the page.
How It Works
The server loops through the files sent to the server and loads each of them into a CImage object. If the file could be loaded successfully, the server generates a temporary file name and tries to save the image to that file name in PNG format. If that is successful, the server loads the file into an object that exposes the data through the IWriteStream interface and hooks that up to an OLE DB accessor. The server then calls a stored procedure using that accessor to add the image to the database along with information such as its width, height, and bits per pixel.
Each image added to the database causes an IMG element to be added to the response. The SRC attribute of the IMG is a URL to this page. The presence of a query string indicates that the server should send back image data retrieved from the database rather than an HTML page. In this example, the query string just contains the ID of the database record holding the image. This ID is used as a parameter to a stored procedure that returns the image data that is then written to the client.
- SQL Server
AtlHresultFromLastError | BEGIN_HANDLER_MAP | BEGIN_REPLACEMENT_METHOD_MAP | CAtlFile::Create | CAtlFile::GetSize | CCommand::Open | CDataSource::OpenFromFileName | CHttpMap::GetCount | CHttpMap::GetNextValue | CHttpMap::GetStartPosition | CHttpMap::Lookup | CHttpRequest::FileMap | CHttpRequest::GetFormVars | CHttpRequest::GetMethod | CHttpRequest::HTTP_METHOD_HEAD | CHttpRequestParams::BaseMap | CHttpResponse::AppendHeader | CHttpResponse::ClearResponse | CHttpResponse::Flush | CHttpResponse::GetServerContext | CHttpResponse::SetCacheControl | CHttpResponse::SetContentType | CHttpResponse::SetExpires | CHttpResponse::WriteLen | CImage | CImage::GetBPP | CImage::GetHeight | CImage::GetWidth | CImage::Load | CImage::Save | COleDateTime | COleDateTime::COleDateTime | COleDateTimeSpan | CRequestHandlerT::FormFlags | CRequestHandlerT::MaxFormSize | CRowset::MoveFirst | CSession::Open | END_HANDLER_MAP | END_REPLACEMENT_METHOD_MAP | HANDLER_ENTRY | IHttpFile | IHttpFile::GetContentType | IHttpFile::GetFileName | IHttpFile::GetFileSize | IHttpFile::GetFileSize | IHttpFile::GetFullFileName | IHttpFile::GetParamName | IHttpFile::GetTempFileName | IHttpServerContext | IHttpServerContext::GetServerVariable | OLE DB Consumer Templates | REPLACEMENT_METHOD_ENTRY