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:
- Within your Data Service, switch to Endpoint Configuration.
- Set the Data Services input format to binary.
- Create a binary file form parameter (e.g., datafile).
- Switch back to the Data Service REST Job (graph view).
- Add the FlatFileReader component and set its URL to ‘request:part:datafile’ to access the parameter.
- Connect the FlatFileReader’s output port to a FlatFileWriter component.
- 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.
- 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:
- Create a dictionary entry that you’ll use to store the filename.
- 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.
- 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.