Last active
January 9, 2020 09:57
-
-
Save belazer/edb5e40b18cf5fdabb6d2d60bbb9c71c to your computer and use it in GitHub Desktop.
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
const axios = require('axios'); | |
const qs = require('qs'); | |
const uniqid = require('uniqid'); | |
const data = {"assets": [ | |
{"url": "https://via.placeholder.com/150", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/151", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/152", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/153", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/154", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/155", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/156", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/157", "name": "test.png"}, | |
{"url": "https://via.placeholder.com/158", "name": "test.png"} | |
]}; | |
const run = async () => { | |
const failed = {}; | |
for (const asset of data.assets) { | |
try { | |
console.log(asset.url); | |
const uniqueIdentifier = uniqid(); //Create Unique ID | |
const queryparams = qs.stringify({ | |
key: "KEY", | |
url: asset.url, | |
path: `PROJECTID-STAGE/${uniqueIdentifier}_${asset.name}` | |
}) | |
await axios.post(`https://www.filestackapi.com/api/store/S3?${queryparams}`) | |
.then(function (response) { | |
console.log(response.data); | |
}) | |
.catch(function (error) { | |
console.log(error); | |
}); | |
} catch(e) { | |
failed[asset.url] = e; | |
} | |
} | |
console.log(JSON.stringify(failed, null, 2)); | |
} | |
run().then(() => console.log('Ready')).catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment