Skip to content
Permalink
Browse files

Support for returning base64 coded results from GetMap and GetPrint

  • Loading branch information
mhugent committed Apr 13, 2013
1 parent 093d503 commit 76d1f955c019c3d42cbab29ce2d147acd233b54a
Showing with 17 additions and 5 deletions.
  1. +16 −5 src/mapserver/qgshttprequesthandler.cpp
  2. +1 −0 src/mapserver/qgsrequesthandler.h
@@ -98,7 +98,8 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
{
bool png8Bit = ( mFormat.compare( "image/png; mode=8bit", Qt::CaseInsensitive ) == 0 );
bool png1Bit = ( mFormat.compare( "image/png; mode=1bit", Qt::CaseInsensitive ) == 0 );
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit && !png1Bit )
bool isBase64 = mFormatString.endsWith( ";base64", Qt::CaseInsensitive );
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit && !png1Bit && !isBase64 )
{
QgsDebugMsg( "service exception - incorrect image format requested..." );
sendServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormat + "' is not supported in the GetMap request" ) );
@@ -129,6 +130,11 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );
}

if ( isBase64 )
{
ba = ba.toBase64();
}

sendHttpResponse( &ba, formatToMimeType( mFormat ) );
}
}
@@ -293,6 +299,10 @@ void QgsHttpRequestHandler::sendServiceException( const QgsMapServiceException&

void QgsHttpRequestHandler::sendGetPrintResponse( QByteArray* ba ) const
{
if ( mFormatString.endsWith( ";base64", Qt::CaseInsensitive ) )
{
*ba = ba->toBase64();
}
sendHttpResponse( ba, formatToMimeType( mFormat ) );
}

@@ -408,17 +418,18 @@ void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request,
}
else //capabilities format or GetMap format
{
QString formatString = parameters.value( "FORMAT" );
mFormatString = parameters.value( "FORMAT" );
QString formatString = mFormatString;
if ( !formatString.isEmpty() )
{
QgsDebugMsg( QString( "formatString is: %1" ).arg( formatString ) );

//remove the image/ in front of the format
if ( formatString.compare( "image/png", Qt::CaseInsensitive ) == 0 || formatString.compare( "png", Qt::CaseInsensitive ) == 0 )
if ( formatString.contains( "image/png", Qt::CaseInsensitive ) == 0 || formatString.compare( "png", Qt::CaseInsensitive ) == 0 )
{
formatString = "PNG";
}
else if ( formatString.compare( "image/jpeg", Qt::CaseInsensitive ) == 0 || formatString.compare( "image/jpg", Qt::CaseInsensitive ) == 0
else if ( formatString.contains( "image/jpeg", Qt::CaseInsensitive ) == 0 || formatString.contains( "image/jpg", Qt::CaseInsensitive ) == 0
|| formatString.compare( "jpg", Qt::CaseInsensitive ) == 0 )
{
formatString = "JPG";
@@ -427,7 +438,7 @@ void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request,
{
formatString = "SVG";
}
else if ( formatString.compare( "pdf", Qt::CaseInsensitive ) == 0 )
else if ( formatString.contains( "pdf", Qt::CaseInsensitive ) == 0 )
{
formatString = "PDF";
}
@@ -48,6 +48,7 @@ class QgsRequestHandler
protected:
/**This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')*/
QString mFormat;
QString mFormatString; //format string as it is passed in the request (with base
QString mService;
};

0 comments on commit 76d1f95

Please sign in to comment.
You can’t perform that action at this time.