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

async rename #61

Closed
benkaiser opened this issue Sep 25, 2014 · 2 comments
Closed

async rename #61

benkaiser opened this issue Sep 25, 2014 · 2 comments

Comments

@benkaiser
Copy link

Hello,

I noticed the rename function uses a return value. Can this be done inside a callback? or would it simply return undefined? I need to fetch an ID for the image which would be a database call like so:

rename: function (fieldname, filename) {
  getNextPhotoId(function(id){
    return id + ".jpg";
  }
}

is this possible with multer?

@mdaffin
Copy link

mdaffin commented Sep 26, 2014

That won't work as getNextPhotoId will return before your callback has even started.

You probably want to use onFileUploadComplete instead and rename the file your self in the callback.

onFileUploadComplete: function (file) {
  getNextPhotoId(function(id){
    fs.rename(file, id + ".jpg", function(err) {
      // Handel error and any further code
    });
  }
}

@benkaiser
Copy link
Author

@James147 awesome. Thanks for the tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants