Upload binary file with a data service

I would like to use a data service to allow users to upload a zip file that is then processed by a graph. It looks like you can create form parameters that are binary. And running the data service, it allows you to pick a file to upload, I’m just not sure how to accept the file and then save it to disk someone in order to process by my graph.

Hi Brandon,

You are on the right track with the binary form parameter for the file upload. Once you create the parameter, you can access it with ‘request:part:<form_parameter_name>’ in the Reader component’s URL and save it with a Writer component afterward. Here is the step-by-step guide:

  1. Within your Data Service, switch to Endpoint Configuration.
  2. Set the Data Services input format to binary.
  3. Create a binary file form parameter (e.g., datafile).
  4. Switch back to the Data Service REST Job (graph view).
  5. Add the FlatFileReader component and set its URL to ‘request:part:datafile’ to access the parameter.
  6. Connect the FlatFileReader’s output port to a FlatFileWriter component.
  7. To send the file over the edge, you want the metadata to contain a single byte field. Additionally, remove the 'Record delimiter’ and 'Default delimiter’ valuesfor the record and set the ‘EOF as delimiter’ property to true.
  8. Lastly, set the FlatFileWriter’s URL to where you want to save the file (e.g., ${DATAIN_DIR}/upload.zip)

If you want to save the file with its original name, use the getRequestPartFilename CTL function.

In such case, you need to:

  1. Create a dictionary entry that you’ll use to store the filename.
  2. Acquire the filename in CTL with the getRequestPartFilename function and store it in the created dictionary. You can use the GetJobInput component for this purpose.
  3. Use the dictionary in the FlatFileWriter component’s URL - ‘dict:<dictionary_entry_name>:source’. Note that you must put components accessing the same dictionary into different phases. Therefore, please place the GetJobInput component into a lower phase than the FlatFileWriter component.

Kind regards.

This worked so perfectly Ladislav, thank you very much.