Exercise 10 Working with Resources
Data C:\FMEData2018\Data\CellSignals\CellSignal.csv
Overall Goal To demonstrate how to upload a file and download a file using the REST API.
Demonstrates The calls for managing resources

Through the REST API, you will have access to the Resources available in the FME Server. You can list files, upload files, and delete files all using the REST API. This is helpful in a web application if you would like to direct data to a certain area in the FME Server.


Ricky RESTless says...
Most file management can be handled through the REST API. This means in a web application can have users upload files to the server, run a translation, and then return a file to the user. These calls are also in the FME JavaScript API and will be used later in the course.

Uploading a File

This call will upload a file to the data folder in your resources folder. The filename is specified in the Content-Disposition parameter. If you wanted to specify a directory in the data folder simply write the folder name after filesys. Uploading a file could be useful in a web application if it is requesting data from a user and inputting that data into a workspace.


1) Enter the following URL and Headers into Postman

In Postman click the plus symbol to open a new tab.

POST http://<yourServerHost>/fmerest/v3/resources/connections/FME_SHAREDRESOURCE_DATA/filesys/

Headers:

  • Content-Type: application/octet-stream

  • Accept: application/json

  • Content-Disposition: attachment; filename= "uploadingfiles.csv"

  • Authorization: fmetoken token= <yourToken>


2) Upload a File in Postman

To upload a file in Postman. Switch to the Body tab. Select binary. The press Choose Files and navigate to

C:\FMEData2018\Data\CellSignals\CellSignal.csv

Click Send! Then, review the response


Optional Query String Parameters

Query string parameters are added at the end of the URL. If you wished to include these it would the URL would look like this:

http://<yourServerHost>/fmerest/v3/resources/connections/FME_SHAREDRESOURCE_DATA/filesys?createDirectories=true&overwrite=false
Parameter Value Description
createDirectories True | **false** Create directories in the path if they do not exist
overwrite True | **false** Overwrite the file if it already exists

Listing Files

This call will list the files in a resource. Listing files in a resource could be used in either a workspace or a web application. A possible use case could be creating a workspace to list all files in a resource and create an excel spreadsheet that is organized by the date uploaded.


3) Enter in the Following URL and Headers in Postman

GET http://<yourServerHost>/fmerest/v3/resources/connections/FME_SHAREDRESOURCE_DATA/filesys/

Headers:

  • Accept: application/json

  • Authorization: fmetoken token=<yourToken>


4) View the Response in Postman


Downloading a File

The downloading file call is particularly useful in a web application. This can be used to return file to a user. This call can also be used in a workspace to download text files.

This call downloads a file from a resource connection either as an inline resource or as an attachment. The 'disposition' parameter is only relevant for some REST clients. In particular, Internet Explorer behaves poorly without an attachment disposition header. This web page will only display the response body instead of downloading the file, so REST clients should inspect the Content-Disposition header and handle the download.

This call will look into the Resources/Data directory to find uploadingfiles.csv.


5) Enter in the Following URL and Headers in Postman

POST http://<yourServerHost>/fmerest/v3/resources/connections/FME_SHAREDRESOURCE_DATA/download/uploadingfiles.csv

Headers:

  • Accept: application/octet-stream

  • Authorization: fmetoken token=<yourToken>

  • Content-Type: application/x-www-form-urlencoded


6) Enter in the body of the call

To enter in the body of the call. Click the body tab, check raw and then paste the contents below.

accept=contents&disposition=inline

Hit Send! Then, review the response in Postman

Parameters:

Parameter Value Description
disposition inline/attachment Inline will display how to retrieve the resource using the 'Content-Disposition' header. This parameter is only relevant for some REST clients (primarily web browsers). If no disposition is selected, then a header is not set.
Path Path, relative to the resource connection (for example, uploading.csv)
Resource Name of a resource connection. Can contain only alphanumeric characters. (for example, FME_SHAREDRESOURCE_DATA)

CONGRATULATIONS
By completing this exercise you have learned how to:
  • Upload a file using the REST API
  • List files using the REST API
  • Download files using the REST API

results matching ""

    No results matching ""