generated from typescriptstarter/ts-backend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5834a11
commit 99851ba
Showing
20 changed files
with
6,785 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ get402.json | |
dist/ | ||
.rabbi/config.json | ||
keys/ | ||
downloads | ||
.runcache | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
const http = require('http'); | ||
const fs = require('fs'); | ||
|
||
import { resolve } from 'path' | ||
|
||
import { createWriteStream } from 'fs' | ||
|
||
const axios = require('axios') | ||
|
||
async function downloadImage () { | ||
const url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/p/bqZW7p5X2I7LZg1OqP_-UjdhDEpzbuUmD18OtwfqvBIqJW05y4bqqaZGgngAd_8t/n/fr4eeztjonbe/b/vpaas-recordings-prod-8x8-us-ashburn-1/o/vpaas-magic-cookie-30f799d005ea4007aaa7afbf1a14cdcf/waqcxosifleqyirx/sampleappworthytruthsclarifyclearly_2022-12-21-17-53-31.mp4' | ||
|
||
const path = resolve(__dirname, 'images', 'code.jpg') | ||
const writer = createWriteStream(path) | ||
|
||
const response = await axios({ | ||
url, | ||
method: 'GET', | ||
responseType: 'stream' | ||
}) | ||
|
||
response.data.pipe(writer) | ||
|
||
return new Promise((resolve, reject) => { | ||
writer.on('finish', resolve) | ||
writer.on('error', reject) | ||
}) | ||
} | ||
|
||
|
||
|
||
export async function main() { | ||
|
||
const url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/p/bqZW7p5X2I7LZg1OqP_-UjdhDEpzbuUmD18OtwfqvBIqJW05y4bqqaZGgngAd_8t/n/fr4eeztjonbe/b/vpaas-recordings-prod-8x8-us-ashburn-1/o/vpaas-magic-cookie-30f799d005ea4007aaa7afbf1a14cdcf/waqcxosifleqyirx/sampleappworthytruthsclarifyclearly_2022-12-21-17-53-31.mp4' | ||
|
||
const file = fs.createWriteStream("file.jpg"); | ||
const request = http.get(url, function(response) { | ||
response.pipe(file); | ||
|
||
// after download completed close filestream | ||
file.on("finish", () => { | ||
file.close(); | ||
console.log("Download Completed"); | ||
}); | ||
}); | ||
|
||
|
||
} | ||
|
||
if (require.main === module) { | ||
|
||
downloadImage() | ||
|
||
//main() | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
const Downloader = require("nodejs-file-downloader"); | ||
|
||
const S3 = require('aws-sdk').S3 | ||
|
||
const S3S = require('s3-streams'); | ||
|
||
import { createReadStream } from "fs"; | ||
|
||
(async () => { | ||
//Wrapping the code with an async function, just for the sake of example. | ||
// | ||
const url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/p/bqZW7p5X2I7LZg1OqP_-UjdhDEpzbuUmD18OtwfqvBIqJW05y4bqqaZGgngAd_8t/n/fr4eeztjonbe/b/vpaas-recordings-prod-8x8-us-ashburn-1/o/vpaas-magic-cookie-30f799d005ea4007aaa7afbf1a14cdcf/waqcxosifleqyirx/sampleappworthytruthsclarifyclearly_2022-12-21-17-53-31.mp4' | ||
|
||
const downloader = new Downloader({ | ||
url, | ||
directory: "./downloads", //This folder will be created, if it doesn't exist. | ||
onProgress: function (percentage, chunk, remainingSize) { | ||
//Gets called with each chunk. | ||
console.log("% ", percentage); | ||
console.log("Current chunk of data: ", chunk); | ||
console.log("Remaining bytes: ", remainingSize); | ||
}, | ||
}); | ||
|
||
|
||
|
||
|
||
try { | ||
const {filePath,downloadStatus} = await downloader.download(); //Downloader.download() resolves with some useful properties. | ||
|
||
var upload = S3S.WriteStream(new S3(), { | ||
Bucket: 'pow.co', | ||
Key: 'powco_recordings/my-key' | ||
}); | ||
|
||
createReadStream(filePath).pipe(upload); | ||
|
||
var s3 = new S3(); | ||
|
||
//configuring parameters | ||
var params = { | ||
Bucket: 'pow.co', | ||
Body : createReadStream(filepath), | ||
Key : "powco_recordings/"+Date.now()+"_"+path.basename(filepath) | ||
}; | ||
|
||
s3.upload(params, function (err, data) { | ||
//handle error | ||
if (err) { | ||
console.log("Error", err); | ||
} | ||
|
||
//success | ||
if (data) { | ||
console.log("Uploaded in:", data.Location); | ||
} | ||
}); | ||
|
||
console.log("All done", {filePath}); | ||
} catch (error) { | ||
//IMPORTANT: Handle a possible error. An error is thrown in case of network errors, or status codes of 400 and above. | ||
//Note that if the maxAttempts is set to higher than 1, the error is thrown only if all attempts fail. | ||
console.log("Download failed", error); | ||
} | ||
})(); |
Oops, something went wrong.