Commit 85df7df4 authored by James Calfee's avatar James Calfee
Browse files

Serve image via URL redirect. #2.

parent 2c63f1d9
......@@ -28,13 +28,13 @@ Tarantool database should be available on port 3401 of your local host.
# GET
> curl http://localhost:3234/<hash256(data)>/<[optional_file_name]>
> curl -L http://localhost:3234/<hash256(data)>/<[optional_file_name]>
The `optional_file_name` is ignored but should be provided to help users and applications understand the URL.
#### Example Download
> curl -v http://localhost:3234/a190c0596a37398427e51bcbee7c94f1007075629828d62005735c6c2d2ffeef/blue_red_pill.jpg > $HOME/Pictures/blue_red_pill.jpg
> curl -Lv http://localhost:3234/a190c0596a37398427e51bcbee7c94f1007075629828d62005735c6c2d2ffeef/blue_red_pill.jpg > $HOME/Pictures/blue_red_pill.jpg
#### Example Upload (user `steem` signed using a test key)
......
......@@ -17,21 +17,26 @@ router.get('/:hash/:filename?', function *() {
const {hash} = this.params
const key = `${hash}`
yield new Promise(resolve => {
const params = {Bucket: amazonBucket, Key: key};
s3.getObject(params, (err, data) => {
if(err) {
console.log(err)
this.status = 400
this.statusText = `Error fetching ${key}.`
resolve()
return
}
this.set('Last-Modified', data.LastModified)
this.body = new Buffer(data.Body.toString('binary'), 'binary')
resolve()
})
})
const params = {Bucket: amazonBucket, Key: key, Expires: 60};
const url = s3.getSignedUrl('getObject', params);
// console.log("get URL is", url);
this.redirect(url)
// yield new Promise(resolve => {
// const params = {Bucket: amazonBucket, Key: key};
// s3.getObject(params, (err, data) => {
// if(err) {
// console.log(err)
// this.status = 400
// this.statusText = `Error fetching ${key}.`
// resolve()
// return
// }
// this.set('Last-Modified', data.LastModified)
// this.body = new Buffer(data.Body.toString('binary'), 'binary')
// resolve()
// })
// })
} catch(error) {console.error(error)}
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment