TypeScript SDK Upload Connector File

I am trying to use the TypeScript SDK to upload a connector file dependency (i.e. JDBC driver, etc.). I can easily do this with the Postman collection call, but for whatever reason, I keep getting either 400 or 500 errors whenever I try with the SDK. The SDK is supposed to build the FormData object for you, so I am just passing the file stream into the file parameter of the function. Any ideas? Here is my code:

//Upload connector files. connector_files is a CSV of the referenced JAR files
const connectorFiles = localSource.connectorAttributes.connector_files;
if (connectorFiles) {
    const connectorFileList = connectorFiles.split(",");
    for (const connectorFileName of connectorFileList) {
        const relativeFilePath = `connectorLib/${connectorFileName}`;
        winston.info(`Uploading connector library file [${relativeFilePath}]`);
        let fullFilePath;
        let fileStream;
        try {
            fileStream = fs.readFileSync(relativeFilePath);
            fullFilePath = path.resolve(relativeFilePath);
            winston.info(fullFilePath);
        } catch (error) {
            winston.error(`Could not find connector library dependency [${relativeFilePath}]. Put the file in the directory and try again`);
            process.exit(1);
        }

        await sourcesApi.importConnectorFile({
            sourceId: currentTartgetSource.id,
            file: fileStream
        });
    }
}

@patrickboston ,
Try using fs.createReadStream instead of fs.readFileSync when reading the file—change your code to pass a ReadStream to importConnectorFile, like this:

fileStream = fs.createReadStream(relativeFilePath);

using fs.createReadStream throws the following:

 {
      detailCode: '400.1 Bad request content',
      trackingId: 'ce32a6e7a9ed4c4b80915b30be78e8b0',
      messages: [
        {
          locale: 'und',
          localeOrigin: 'REQUEST',
          text: 'The request was syntactically correct but its content is semantically invalid.'
        },
        {
          locale: 'en-US',
          localeOrigin: 'DEFAULT',
          text: 'The request was syntactically correct but its content is semantically invalid.'
        }
      ],
      causes: []
    }

Using the original method of fs.readFileSync throws the following:

{
      messages: [
        {
          localeOrigin: 'REQUEST',
          text: 'An internal fault occurred.',
          locale: 'en-US'
        },
        {
          localeOrigin: 'DEFAULT',
          text: 'An internal fault occurred.',
          locale: 'en-US'
        }
      ],
      detailCode: '500.0 Internal fault',
      trackingId: '43a3ec30bf124585b723477e9c77c675'
    }

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.