Skip to content

Instantly share code, notes, and snippets.

@belazer
Last active January 9, 2020 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belazer/edb5e40b18cf5fdabb6d2d60bbb9c71c to your computer and use it in GitHub Desktop.
Save belazer/edb5e40b18cf5fdabb6d2d60bbb9c71c to your computer and use it in GitHub Desktop.
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