Skip to Content

Storing PDF-File from Webservice-Result as Attachment

Feb 06, 2017 at 07:42 AM


avatar image
Former Member

Hello everybody,

I invoked a REST web service call to get a PDF file from a server. The web service works fine and I get a response.

But when i want to store the PDF file in an attachment folder of the Outbound Delivery. Getting the attachment folder, creating the file and all that stuff works fine as well.

but my PDF file is empty. But i just realize that somebody has already made a request for the same problem but without answer. Please can you help me?

Best Regards


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Horst Schaude
Feb 09, 2017 at 01:30 PM

Hello Stephane,

Did you verify that content is handed over from the web service?

Did you provided the correct mine type code?


Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Horst thank you for your reply,

as you ask me i check it once again nd i'm sure that the content is handed over from the web Service

the Mine Code is correctly provide. Hier my Code

myRest wsid

the code hier

import ABSL;
import BASIS.Global ;
import AP.Common.GDT;

var ScenarioName = "Scenario";
var ServiceName = "service";

var HttpMethod = "GET";
var HttpResource = ""; 
var ContentType = "application/pdf;"; 
var Body = ""; 

var HeaderParameter : collectionof NameAndValue; 
var URLParameter : collectionof NameAndValue;
var URLParameterEntry : NameAndValue;

URLParameterEntry.Name = "code";
URLParameterEntry.Value = "22B2158E295CC514791E78FB4E938A4A0BCF27D711096DBF";

var ws_result = WebServiceUtilities.ExecuteRESTService (ScenarioName, ServiceName, HttpMethod, HttpResource, URLParameter, HeaderParameter, ContentType, Body);

var documentContent;
var documentType;
var documentCode;
var requestURL;

if (!ws_result.IsInitial())
	documentContent = Binary.ToBase64String(Binary.ParseFromString(ws_result.Content));
	documentType = ws_result.ContentType;
	documentCode = ws_result.Code;
	documentCode = documentCode.Trim(" ");
	requestURL = ws_result.RequestURL;

if(documentCode == "200")
	var attachmentFolder = this.AttachmentFolder;
		var docTypeCode : DocumentTypeCode;
		docTypeCode.content = "10001";
		var docAltName = Context.GetCurrentSystemDateTime().ToString();
		var docName = docAltName + ".pdf";
		var docDescr : Description;
		docDescr.content = "dscr";
		var docFileContentBinaryObject : BinaryObject;
		docFileContentBinaryObject.characterSetCode = "ANSI";
		docFileContentBinaryObject.content = Binary.ParseFromBase64String(documentContent);
		attachmentFolder.CreateFile(docTypeCode, docName, docAltName, docDescr, docFileContentBinaryObject);

hier the link. DHL link

i try to attach this pdf file in the Attachment of a material for example.

but the pdf file is empty.

Please did yyou have some idea? or propositions?



dhl.png (6.9 kB)

Hello Stephane,

A PDF contains not only binary but in most cases a mix of strings and binary.
Therefore the Binary.ParseFromString(...) wont work.

Futhermore I suggest to use the action "CreateFile" of the Root node of the AttachmentFolder DO.


Former Member
Horst Schaude

Hi Horst,

i try all those stoff without success. what was made, was just create an external tool which convert the pdf file in Base64String and with the WS just get the file already coded.

But i thank you for your help Horst.