SXI Forum

A place to collect usefull tips, tricks and implementation strategies.

You are not logged in.

#1 10-07-2019 11:04:23

MarekR
Member
Registered: 21-02-2019
Posts: 19

Output a file from base64

This is an example of how to write a file to disk from a base64 string in memory.

You will need the following connector:

   <Connector id="WriteFile" type="FileSystem">
      <Connection xsi:type="sxi:FileSystem">
        <sxi:Write>
          <sxi:SaveLocation>C:\Path\Where\File\Will\Be\Saved</sxi:SaveLocation>
          <sxi:FileName>$FileName$</sxi:FileName>
        </sxi:Write>
      </Connection>
      <sxi:ReturnCodes>
        <sxi:Success/>
        <sxi:RecoverableError/>
      </sxi:ReturnCodes>
    </Connector>

Notice that the FileName is between two "$" (This will be changed to "~#~" in a future release) this indicates that "FileName" is a field in memory that will be used when a file is created. You could also put in a static value here by removing the "$"'s.

You can use a "MemoryDataManipulation" to set the "FileName" for the connector. For Example:

   <sxi:DataDefinition name="SetFileName">
      <sxi:Fields>
        <sxi:Field name="na">
          <sxi:Rules>
            <sxi:Default>Fred.txt</sxi:Default>
          </sxi:Rules>
          <sxi:OutputField>FileName</sxi:OutputField>
        </sxi:Field>
      </sxi:Fields>
    </sxi:DataDefinition>

Where I have "na" you could also use an field in memory with a valid file name and file extension.

Next you need to create the file using this mapping:

<Create dataDefinition="WriteFileToDisk" connectorId="WriteFile" source="C:\Path\Where\File\Will\Be\Saved"/>

The "source" attribute is the path where the file will be written. If you make the source "na" the path in the connector will be used.

The DataDefinition "WriteFileToDisk" looks as follows:

    <sxi:DataDefinition name="WriteFileToDisk">
      <sxi:Fields>
        <sxi:Field name="mData">
          <sxi:OutputField datatype="base64">FileContents</sxi:OutputField>
        </sxi:Field>
      </sxi:Fields>
    </sxi:DataDefinition>

"mData" is the field in memory containing the base64 we want to write to a file.

"OutputField" must contain the attribute datatype="base64"

The "Outputfield" for the "mData" MUST be the word FileContents.

When this action is run the filesystem connector will create a file "fred.txt" in the following path "C:\Path\Where\File\Will\Be\Saved".

Offline

Board footer

Powered by FluxBB