VMware Cloud Community
tough_siberian_
Enthusiast
Enthusiast
Jump to solution

HTTP-REST plugin - how to PUT binary content?

Hello.

Does anybody know what is the proper way to use HTTP-REST Plugin methods to upload binary content to the server using PUT method?

I have no difficulties to upload a text file (even with the size of few megabytes), but even with a small binary file (30-40 KB) server returns HTTP error 500.

Changing the value of contentType field to "application/octet-stream"  doesn't help.

Thank you.

0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

Based on a recent request, one of my colleagues provided some example code that uploads a file using the HTTP-REST plug-in ...

file = input variable name. vCO Object type is MimeAttachment

restOperation = input variable name. vCO Object type is REST:RESTOperation

Prior to the code specified here, you would need to prepare whatever your inputParametersValues are for the request:

// Set the request contentType to the file's mime type

var request = restOperation.createRequest(inParametersValues, file.content);

request.contentType = file.mimeType;

System.log("Request: "+request);

System.log("Request URL: "+request.fullUrl);

// Set whatever additional headers you may need here:

// request.setHeader("headerName"," headerValue");

// Execute the request:

var response = request.execute();

System.log("Response: "+response);

// prepare an output:

var statusCodeAttribute = response.statusCode;

System.log("Status code: "+statusCodeAttribute);

Hopefully this is enough to help you out...

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
4 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

I have not yet been able to work with binary content using the HTTP-REST plug-in. I had hoped to do so for some of the vCO classes I teach internally. As a result, I have submitted a Feature Request to have this added to the plug-in. If you (or anyone else here) figures out a way to put or get binary content, I'm quite interested in the solution as well Smiley Happy

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Based on a recent request, one of my colleagues provided some example code that uploads a file using the HTTP-REST plug-in ...

file = input variable name. vCO Object type is MimeAttachment

restOperation = input variable name. vCO Object type is REST:RESTOperation

Prior to the code specified here, you would need to prepare whatever your inputParametersValues are for the request:

// Set the request contentType to the file's mime type

var request = restOperation.createRequest(inParametersValues, file.content);

request.contentType = file.mimeType;

System.log("Request: "+request);

System.log("Request URL: "+request.fullUrl);

// Set whatever additional headers you may need here:

// request.setHeader("headerName"," headerValue");

// Execute the request:

var response = request.execute();

System.log("Response: "+response);

// prepare an output:

var statusCodeAttribute = response.statusCode;

System.log("Status code: "+statusCodeAttribute);

Hopefully this is enough to help you out...

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
tough_siberian_
Enthusiast
Enthusiast
Jump to solution

Thanks,

I will try your code out.

However, there is another problem - how to create a MimeAttachment from binary content received with HTTP-REST plugin?

Scenario is simple - I want to download a binary content from one URL and upload it to another. How to create a MimeAttachment from downloaded content?

Will it be correct if I use FileWriter (the class for writing text into files) to write binary content into file for later construction of MimeAttachment from this file?

Will "RESTResponse.contentAsString" property transfer binary content properly without loosing non-textual data?

Or maybe there's another, simpler way of doing that?

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Take a look at the workflow I attached in this post: Re: Orchestrator 5.1 REPORT-All VMs in Datacentre and create a CSV -- it uses fileWriter to write a csv file... in the last scriptable task element, I create a MimeAttachment object from that file. You should be able to do the same if you figure out a proper way to create the binary file.. I have never attempted to use fileWriter to create anything other than a text based file... Unfortunately, the retrieval of binary files using the HTTP-REST plug-in has not yet been implemented.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter