Skip to content

Commit

Permalink
changes the hex filename to a more robust version #32
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcarlisle committed Oct 6, 2016
1 parent a7219d5 commit 561b0ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/direct-upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ server.register(require('inert'),
if (request.query.filename) {
// if you upload two items with the same name to the same bucket, the second
// will overwrite the first. These random hashes prevent that from happening
var filename =
crypto.randomBytes(8).toString('hex') +
path.extname(request.query.filename)
var ext = '.' + path.extname(request.query.filename)
var filename = request.query.filename.replace(ext, '') +
crypto.randomBytes(8).toString('hex') + ext
reply(s3.getS3Credentials(s3Config, filename))
} else {
reply('Filename required')
Expand Down
7 changes: 3 additions & 4 deletions examples/direct-upload/lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ module.exports = [
path: '/s3_credentials',
handler: function (request, reply) {
if (request.query.filename) {
var filename =
request.query.filename.split('.')[0] +
crypto.randomBytes(8).toString('hex') +
path.extname(request.query.filename)
var ext = '.' + path.extname(request.query.filename)
var filename = request.query.filename.replace(ext, '') +
crypto.randomBytes(8).toString('hex') + ext
return reply(s3.getS3Credentials(s3Config, filename))
} else {
return reply('Filename required').code(400)
Expand Down
7 changes: 3 additions & 4 deletions examples/sdk-upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ AWS.config.region = process.env.AWS_S3_REGION
**/
function upload (file, filename, callback) {
// creating our new filename
var filenameHex =
filename.split('.')[0] +
crypto.randomBytes(8).toString('hex') +
path.extname(filename)
var ext = '.' + path.extname(filename);
var filenameHex = filename.replace(ext, '') +
crypto.randomBytes(8).toString('hex') + ext;
// loading our bucket name from our environment variables
var bucket = process.env.AWS_S3_BUCKET
// creating a new instance of our bucket
Expand Down
7 changes: 3 additions & 4 deletions examples/sdk-upload/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ var path = require('path')
AWS.config.region = process.env.AWS_S3_REGION

function upload (file, filename, callback) {
var filenameHex =
filename.split('.')[0] +
crypto.randomBytes(8).toString('hex') +
path.extname(filename)
var ext = '.' + path.extname(filename)
var filenameHex = filename.replace(ext, '') +
crypto.randomBytes(8).toString('hex') + ext
var bucket = process.env.AWS_S3_BUCKET
console.log(bucket)
var s3Bucket = new AWS.S3({params: {Bucket: bucket}})
Expand Down

0 comments on commit 561b0ff

Please sign in to comment.