The function uploadToBucket can no longer be referenced or found when adding the imports.
import { PutObjectCommand, S3Client, GetObjectCommand, ListObjectsV2Command } from ("@aws-sdk/client-s3");
import { getSignedUrl, S3RequestPresigner } from ("aws-sdk/s3-request-presigner");
import {axios} from ("axios");
// Upload a file to Amazon S3
async function uploadToBucket(options){
console.log("[RingCentral App Server] Options are ", options);
try {
console.log("[RingCentral App Server] Starting cloud upload...");
const start = Date.now();
let s3Client;
// Depending on the cloudProvider, set up the S3 client configuration
if (options.cloudProvider === "AWS") {
console.log("[RingCentral App Server] Configuring for AWS S3...");
s3Client = new S3Client({
region: options.iparams.recordingBucketRegionAWS,
credentials: {
accessKeyId: options.iparams.recordingBucketAccessKey,
secretAccessKey: options.iparams.recordingBucketSecretKey,
},
});
} else if (options.cloudProvider === "GCS") {
console.log("[RingCentral App Server] Configuring for Google Cloud...");
s3Client = new S3Client({
region: options.iparams.recordingBucketRegionGC,
endpoint: "https://storage.googleapis.com",
credentials: {
accessKeyId: options.iparams.recordingBucketAccessKey,
secretAccessKey: options.iparams.recordingBucketSecretKey,
},
});
}
console.log("[RingCentral App Server] Fetching the recording data...");
const recordingResponse = await axios.get(options.recordingUri, {
decompress: false,
responseType: "arraybuffer",
});
console.log('[RingCentral App Server] Received recording response.', recordingResponse);
const recordingFile = recordingResponse.data;
console.log("[RingCentral App Server] Generating a random ID for the file key...");
// Created at: createRecordingInfoObject(contactid) -> recording-{contactId}-{mmss}-{yyyyMMdd}.mp3
const key = options.fileName;
console.log(`[RingCentral App Server] Generated key for file: ${key}`);
console.log("[RingCentral App Server] Sending upload command...");
const command = new PutObjectCommand({ Bucket: options.iparams.recordingBucketName, Key: key });
let signedUri = await getSignedUrl(s3Client, command, { expiresIn: 3600 });
let resp = await axios.put(signedUri, recordingFile);
console.log("[RingCentral App Server] Response from uploading recording file: ", resp);
console.log("[RingCentral App Server] File uploaded successfully!");
const end = Date.now();
console.log(`[RingCentral App Server] Execution time: ${end - start} ms`);
console.log("[RingCentral App Server] Cloud upload completed successfully.");
// renderData(null, "Cloud upload completed successfully");
} catch (err) {
console.error("[RingCentral App Server] Error encountered during cloud upload:", err);
// renderData(err);
}
}
Aside from that I am also receivin g the following error when loading the JS file in our browser app:
Refused to execute script from ‘http://localhost:10001/iframe/agent/scripts/openai/bucketHelper.js’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled.
I do not know what is going wrong because I thought you could use import statements like this.
I have tried to use required and scripts refences in the html but it did not work.