How to send/receive file as an attachment with metadata using TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON.

How to send/receive file as an attachment with metadata using TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON.

book

Article ID: KB0073332

calendar_today

Updated On:

Products Versions
TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON 2.1.0, 2.0.0

Description

Description:
As a Web service, TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON can be used to send/receive file as an attachment with metadata. Using the plug-in there are three choices. 
 

1). Base64 encodes the file at use Invoke REST API to send the binary content to the REST Server.

 

2). Send the file first in a multipart/form-data POST and return an ID to the client. The client then sends the metadata with the ID and the server reassociates the file and the metadata.

 

3). Send the metadata first and return an ID to the client. The client then sends the file with the ID and the server reassociates the file and the metadata.

Issue/Introduction

How to send/receive file as an attachment with metadata using TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON.

Environment

Product: TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON Version:2.0.0, 2.1.0 BW Version: All supported BW versions OS: All Supported Operating Systems --------------------

Resolution

We will go for option 1 which consists in reading the file and include the Base64 encoded string as content value inside JSON string. After that, POST the data through Invoke REST API which accepts both forms of data and JSON response based on the Content-Type HTTP header. Refer to the attached project (Filename: Upload_file_Rest_Json.rar) for reference.

Below is the detailed explanation for the sample project

The REST Client process is the client process that reads a .xlsx file into binary content and uses Render JSON activity to render the .xlsx file content and file information into a JSON string. Then use Invoke REST API to send the JSON string to the REST Server;

The Rest Server process is the Server process, which receives the HTTP request from the client and maps the JSON content in the HTTP request to the Subprocess “Persit on the disk.process”, in the subprocess we use Parse JSON activity to parse the JSON content, then use Write File activity to store the file content in the disk.

Additional Information

Web service Api, Json data, metadata 

Attachments

How to send/receive file as an attachment with metadata using TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON. get_app