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

Options to make a thumbnail image #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
[update] do not save thumbnailWidth
Aqid committed Oct 6, 2017
commit 11d9947df6b4d9bdaa562d3bce310a7ae5f19c82
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -140,6 +140,8 @@ Fileupload.prototype.handle = function (ctx, next) {
debug("thumbnail found: %j", req.query[propertyName]);
thumbnail = (req.query[propertyName] === 'true');
continue; // skip to the next param since this value will be hardcoded later
} else if (propertyName === 'thumbnailWidth') {
continue; // do not save thumbnail width
}

// Store any param in the object
@@ -175,9 +177,9 @@ Fileupload.prototype.handle = function (ctx, next) {
if (storedObject.id) delete storedObject.id;
if (storedObject._id) delete storedObject._id;

if(file.thumbnailFilename && storedObject.type.includes('image')) {
if(thumbnail && storedObject.type.includes('image')) {
storedObject.thumbnail = file.thumbnailFilename
sharp(path.join(uploadDir, file.name)).resize(400).toBuffer().then(function (data) {
sharp(path.join(uploadDir, file.name)).resize(req.query['thumbnailWidth'] || 400).toBuffer().then(function (data) {
fs.writeFile(path.join(uploadDir, file.thumbnailFilename), data, function(err) {
if (err) return processDone(err);
debug("Thumbnail renamed after event.upload.run: %j", err || path.join(uploadDir, file.thumbnailFilename));