const { CellsApi, PostClearObjectsRequest } = require("asposecellscloud");
const clientId = process.env.CellsCloudClientId;
const clientSecret = process.env.CellsCloudClientSecret;
const ApiURL = process.env.CellsCloudApiBaseUrl;

const localPath = "D:/aspose-cells-cloud-node/TestData/"
var fs = require('fs');
var path = require('path');
const cellsApi = new CellsApi(clientId, clientSecret,"v3.0",ApiURL);
const AssemblyTestXlsx = "assemblytest.xlsx";
const DataSourceXlsx = "datasource.xlsx";
const dataAssemblyTestXlsx = fs.createReadStream(path.join(localPath, AssemblyTestXlsx));
const dataDataSourceXlsx = fs.createReadStream(path.join(localPath, DataSourceXlsx));

const req = new PostClearObjectsRequest({
  file: { AssemblyTestXlsx: dataAssemblyTestXlsx, DataSourceXlsx: dataDataSourceXlsx },
  objecttype: "Picture"
});


cellsApi.postClearObjects(req)
  .then((result) => {
    console.log("successfully")
    const buff = Buffer.from(result.body.files[0].fileContent, 'base64');
    fs.writeFileSync(result.body.files[0].filename, buff);
  })
  .catch((error) => {
    console.error('Unhandled Promise Rejection:', error);
  });