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

Overriding files when using more than one attachment field (r 0.0.4) #23

Open
ifraixedes opened this issue Apr 30, 2013 · 4 comments
Open

Comments

@ifraixedes
Copy link
Contributor

Hello,

My uses cases required me to have more than one mongoose-field in my schema and I did that, applying the plugin in this way:

 pageSchema.plugin(mongooseAttachments, {
    directory: 'images',
    storage: {
      providerName: 's3',
      options: {
        key: 'my aws key'
        secret: 'my aws secret'
        bucket: 'my aws bucket'
      }
    },
    properties: {
      design_background_image: {
        styles: {
          original: {
            //keep the original file
          },
          ipad_2_landscape: {
            resize: '1024x768>',
            blur: '3x3'
          },
          ipad_2_portrait: {
            resize: '768x1024>',
            blur: '3x3'
          }
      },
      design_banner_image: {
        styles: {
          original: {
            // keep the original file
          },
          ipad_2_landscape: {
            resize: '1024x768>'
          },
          ipad_2_portrait: {
            resize: '768x1024>'
          }
        }
      },
      avatar: {
        styles: {
          original: {
            // keep the original file
          }
        }
      }
    }
  });

The plugin works fine but I realized that if the two or more files to upload in two or more of the specified fields had the same extension then the files uploaded for each transformation were the same for all of them and it was one file between them.

After debugging to try to solve that issue and I could continue using this awesome module, I realized that the problem was (and is because I checked the code in the current file of the tag 0.0.4) in the line 170 of the file lib/attachments.js,

 var storageStylePath = '/' + options.directory + '/' + selfModel.id + '-' + styleName + ext;

and it may fix it quite easy only using the original file name which is figured in the line 151 rather than the document id.

However to avoid to remove the file extension of the file name in each call to forEach function I declared a new variable after the line 160 and I used that variable in the line 170, so the result was something like:

// Below the line 160
var fileNameNoExt = path.basename(attachmentInfo.name, fileExt);

........

// line 170 replaced by
var storageStylePath = '/' + options.directory + '/' + fileNameNoExt + '-' + styleName + ext;

I solved my use case however I am calling 'attach' with and stand-alone rather than using express uploads, and although I think that it would also work well, I cannot be 100% sure, because I haven't tested it in that way.

Could you update the release of npm to carry on using the module from npm rather than use like a local library in my development?

Thanks so much.

@nuarhu
Copy link
Contributor

nuarhu commented Aug 23, 2013

Sorry for the delay, @ifraixedes . Your pull request #26 cannot be merged automatically, anymore. Could you have a look at it after the release? Thanks!

@ifraixedes
Copy link
Contributor Author

Sorry, what you mean with "..after the release?"

@nuarhu
Copy link
Contributor

nuarhu commented Aug 29, 2013

Well, release 0.1.0. It's not out, yet, though. This is for @thepumpkin1979 to decide.

@ifraixedes
Copy link
Contributor Author

Ok, no worries.
Although I thought that you should be able to merge my pull request if you create a new branch from tag 0.0.4 and after merge my pull request to that new branch, as I did to add the modification. I know that you move forward with the new release, however it may be good for people that it is using the old release so the branch may be updated to fix bugs rather than for new features or improvements.

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

No branches or pull requests

2 participants