|
| 1 | +// Load the AWS SDK for Node.js |
| 2 | +const AWS = require('aws-sdk'); |
| 3 | +const path = require('path'); |
| 4 | +const fs = require('fs'); |
| 5 | + |
| 6 | +// Set the region |
| 7 | +AWS.config.update({region: 'us-west', |
| 8 | + accessKeyId: 'YOUR-ACCESS-KEY-ID', //Replace with your access key ID |
| 9 | + secretAccessKey: 'YOUR-SECRET-ACCESS-KEY', //Replace with your secret access key |
| 10 | +}); |
| 11 | + |
| 12 | +// Create S3 service object |
| 13 | +const s3 = new AWS.S3({apiVersion: '2006-03-01', |
| 14 | + endpoint: 'https://us-west.s3.qencode.com' |
| 15 | +}); |
| 16 | + |
| 17 | +// Call S3 to retrieve upload file to specified bucket |
| 18 | +const uploadParams = {Bucket: 'your-bucket-name', Key: '', Body: ''}; //Replace with your bucket name |
| 19 | +const file = "/local/path/to/video.mp4"; // Replace with the file path and name to upload |
| 20 | + |
| 21 | +// Configure the file stream and obtain the upload parameters |
| 22 | +const fileStream = fs.createReadStream(file); |
| 23 | +fileStream.on('error', function(err) { |
| 24 | + console.log('File Error', err); |
| 25 | +}); |
| 26 | +uploadParams.Body = fileStream; |
| 27 | +uploadParams.Key = path.basename(file); |
| 28 | + |
| 29 | +// Call S3 to upload the file to the bucket |
| 30 | +s3.upload (uploadParams, function (err, data) { |
| 31 | + if (err) { |
| 32 | + console.log("Error", err); |
| 33 | + } if (data) { |
| 34 | + console.log("Upload Success", data.Location); |
| 35 | + } |
| 36 | +}); |
0 commit comments