Skip to content

Question: How server images from node/express to angular with authori #1607

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

Closed
ajmarmar opened this issue Feb 3, 2016 · 5 comments
Closed

Comments

@ajmarmar
Copy link

ajmarmar commented Feb 3, 2016

Hi,

How do I serve images from nodejs / Express to angularjs with permission?

In my router controller I've have the following lines:

export function getLogo(req, res) {
    fs.exists(config.repoLogos+'/'+req.params.file, (exists) => {
      if (exists){
        res.sendFile(config.repoLogos+'/'+req.params.file);
      } else {
        res.sendFile(config.repoLogos+'/logodefault.png');
      }
    });

And I get image in controller of angular with:

funciton getLogo(){
    return '/api/resources/logo/' + (this.client.logo || 'default';
}

And the template:

<img ng-src="{{cdc.getLogo()}}" class="img-responsive img-thumbnail img-logo center-block" title="Logo">

Any idea??

PD: I'm sorry for my english. :-P

@ajmarmar
Copy link
Author

ajmarmar commented Feb 4, 2016

I tryed with

function getLogoRaw()
$http.get('/api/resources/logo/' + (this.client.logo || 'default')).then(response => {
        this.logo = response.data;
        //console.log(this.logo);
      }, response => {

      });
}

<img ng-src="{{cdc.getLogoRaw()}}" class="img-responsive img-thumbnail img-logo center-block" title="Logo">

but write the bytes in the html but don't show the image.

@Awk34
Copy link
Member

Awk34 commented Feb 4, 2016

It would probably be easiest for you to set ng-src to a URL. Try something like <img ng-src="{{'/api/resources/logo/' + vm.client.logo}}">

@ajmarmar
Copy link
Author

ajmarmar commented Feb 4, 2016

Hi,

Yes, I did its, but in the route of express I did 2 options:

1.- with Authenticate
router.get('/logo/:file', auth.isAuthenticated(), controller.getLogo);

this is that I want it, but it don't run

2.- Without Authenticate
router.get('/logo/:file', controller.getLogo);

This run fine, but I want to do the 1st option.

Thx.

@Awk34
Copy link
Member

Awk34 commented May 11, 2016

Closed due to inactivity

@Awk34
Copy link
Member

Awk34 commented May 11, 2016

Your # 1 looks like it should work. It's not returning the image?

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