Real time Virus Scan for file upload to box
Hi Community,
I have found this code for real time virus scanning for the file upload using box-node-sdk. Could someone please help if this is the correct way to detect virus in file upload API response. Also, is there any documentation link for this.
const BoxSDK = require('box-node-sdk');
const fs = require('fs');
// Initialize the Box SDK
const sdk = new BoxSDK({
clientID: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
appAuth: {
keyID: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('path/to/your/privatekey.pem'),
passphrase: 'YOUR_PRIVATE_KEY_PASSPHRASE'
}
});
// Set up the client
const client = sdk.getAppAuthClient('enterprise');
// Set up the file upload parameters
const fileParams = {
name: 'testfile.txt',
parent: {
id: 'FOLDER_ID'
}
};
// Set up the virus scanning parameters
const virusScanParams = {
virus_scan: true
};
// Upload the file to Box
client.files.uploadFile(
fileParams,
fs.createReadStream('path/to/your/file.txt'),
virusScanParams
)
.then(file => {
console.log(`File uploaded with ID: ${file.id}`);
})
.catch(err => {
if (err.statusCode === 403 && err.code === 'bad_request') {
console.log('The uploaded file contained a virus and was quarantined by Box');
} else {
console.error(`Error uploading file to Box: ${err}`);
}
});
サインインしてコメントを残してください。
コメント
0件のコメント