Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct public URL for uploads #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions s3router.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function S3Router(options, middleware) {
* give temporary access to PUT an object in an S3 bucket.
*/
router.get('/sign', middleware, function(req, res) {
var filename = (options.uniquePrefix ? uuidv4() + "_" : "") + req.query.objectName;
var filename = options.uniqueFilename ? uuidv4() : ((options.uniquePrefix ? uuidv4() + "_" : "") + req.query.objectName);
var mimeType = req.query.contentType;
var fileKey = checkTrailingSlash(getFileKeyDir(req)) + filename;
// Set any custom headers
Expand All @@ -99,12 +99,18 @@ function S3Router(options, middleware) {
console.log(err);
return res.send(500, "Cannot create S3 signed URL");
}
res.json({
var json = {
signedUrl: data,
publicUrl: '/s3/uploads/' + filename,
filename: filename,
fileKey: fileKey,
});
};
if (typeof options.getWebsiteUrl === 'function') {
json.websiteUrl = options.getWebsiteUrl(fileKey);
} else if (options.getWebsiteUrl === true && options.region) {
json.websiteUrl = 'http://' + S3_BUCKET + '.s3-website.' + options.region + '.amazonaws.com/' + fileKey;
}
res.json(json);
});
});

Expand Down