Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

load assets outside of views dir #57

Closed
mderazon opened this issue Dec 1, 2013 · 7 comments
Closed

load assets outside of views dir #57

mderazon opened this issue Dec 1, 2013 · 7 comments

Comments

@mderazon
Copy link

mderazon commented Dec 1, 2013

would be nice to be able to use this for assets inside node.js code i.e :

app.use(function(req, res, next) {
  res.send(CDN('/path/to/asset'));
});

Is there any way to achieve this ?

Thanks !

@niftylettuce
Copy link
Collaborator

any luck?

@mderazon
Copy link
Author

mderazon commented Dec 4, 2013

I tried to add CDN() to my req object and do something like

app.use(function(req, res, next) {
  res.send(req.CDN('/path/to/asset'));
});

It actually generates a CDN address for the asset but it's not being processed and uploaded to the CDN.
I guess it's because all of the assets are being scanned in the views dir and only on start time.

I am assuming that we have to scan on start time because of the propagation time it takes the files to go from S3 to CDN.

Can't think of any way to work around this...

@niftylettuce
Copy link
Collaborator

maybe just use in your views and since it will
get uploaded you can reference it with res.send?

On Wed, Dec 4, 2013 at 3:05 AM, Michael Derazon notifications@github.comwrote:

I tried to add CDN() to my req object and do something like

app.use(function(req, res, next) {
res.send(req.CDN('/path/to/asset'));
});

It actually generates a CDN address for the asset but it's not being
processed and uploaded to the CDN.
I guess it's because all of the assets are being scanned in the views dir
and only on start time.

I am assuming that we have to scan on start time because of the
propagation time it takes the files to go from S3 to CDN.

Can't think of any way to work around this...


Reply to this email directly or view it on GitHubhttps://github.com//issues/57#issuecomment-29786269
.

@niftylettuce
Copy link
Collaborator

@mderazon how did that work?

@psaia
Copy link

psaia commented Mar 17, 2014

@niftylettuce How would you recommend to handle dynamically generated assets? For example, the adding and displaying of user profile images.

Use case:

someObj.on "uploadComplete", (err, tmpFile) ->
  image = CDN(tmpFile, raw: true)
  saveImage(image)

I would be happy to contribute if you think this type of functionality wouldn't be out of scope for this project. If it is out of scope, do you think handling these on-the-fly uploads would be best handled using the aws-sdk module independently?

@niftylettuce
Copy link
Collaborator

@petesaia why not just use Gravatar for user profile images? I don't know the use case or why you need to handle dynamically generated assets, why aren't they generated ahead of time? Not sure what your service/use case is... there is probably a better way to solve it for you ahead of time (maybe Grunt or caching somehow?).

@psaia
Copy link

psaia commented Mar 17, 2014

@niftylettuce Thanks for the quick reply and suggestion. The use case of an avatar was just an example. For the actual application, users are able to upload multiple images which need to get pushed up to the CDN post-startup. We actually decided to go with pkgcloud for only that component and stick with express-cdn for assets which are perfectly okay to be pre-compiled and pre-cached.

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

No branches or pull requests

3 participants