Skip to content

Commit

Permalink
Support for returning base64 coded results from GetMap and GetPrint
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 13, 2013
1 parent 093d503 commit 76d1f95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/mapserver/qgshttprequesthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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 ) );
}
}
Expand Down Expand Up @@ -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 ) );
}

Expand Down Expand Up @@ -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";
Expand All @@ -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";
}
Expand Down
1 change: 1 addition & 0 deletions src/mapserver/qgsrequesthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit 76d1f95

Please sign in to comment.