Skip to content

Instantly share code, notes, and snippets.

@belazer belazer/test.js
Last active Jan 9, 2020

Embed
What would you like to do?
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
You can’t perform that action at this time.