Skip to content

Instantly share code, notes, and snippets.

@vitorebatista
Last active April 6, 2021 12:12
Show Gist options
  • Save vitorebatista/bfcbf02eb68766f7e01543bc7e3f0f48 to your computer and use it in GitHub Desktop.
Save vitorebatista/bfcbf02eb68766f7e01543bc7e3f0f48 to your computer and use it in GitHub Desktop.
ADVPL Function to download a file using SOAP or REST api
//---------------------------------------------------------------------
/*/{Protheus.doc} Download
Download de arquivo via HTTP (SOAP, REST)
@since 14/03/2016
@version P12
@return logic
/*/
//---------------------------------------------------------------------
Static Function Download( oWebService, cPath, cFileName )
Local xBytes := ReadBytes( cPath )
If Nil == xBytes .Or. 0 <> FError()
Return .F.
EndIf
oWebService:SetContentType( 'application/octet-stream' )
oWebService:SetHeader( 'Content-Disposition', 'attachment; filename=' + cFileName )
oWebService:SetHeader( 'Pragma', 'no-cache' )
oWebService:SetResponse( xBytes )
Return .T.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment