natural-language-api-google/utils/audioUploadToBucket.js

35 lines
678 B
JavaScript

// Imports the Google Cloud client library
const { Storage } = require('@google-cloud/storage')
async function audioUploadToBucket(
bucketName,
filePath,
destFileName,
) {
// [START storage_upload_file]
// Creates a client
const storage = new Storage()
async function uploadFile() {
const options = {
destination: destFileName,
}
await storage.bucket(bucketName).upload(filePath, options)
console.log(`${filePath} uploaded to ${bucketName}`)
}
try {
await uploadFile()
return true
} catch (error) {
console.error(error)
return false
}
// [END storage_upload_file]
}
module.exports = audioUploadToBucket