Error loading image from server

Asked

Viewed 84 times

-1

Hi, I’m trying to upload the image that’s on my server directly to the interface. The server is nodejs with express, already on the front end I’m using the angular Sanitizer.

On the server I have:

server.js: 
    app.use(express.json());

routes.js:
    routes.get('/user_img/id', (req, res) => {
    try {
        const img = req.params.id;
        res.status(200).send(`./tmp/uploads/${img}`);
    }
    catch (e) {
        res.status(404).json({error: 'Image not found'});
    }
});

The answer to the request is this: inserir a descrição da imagem aqui

At the angle I have:

HTML:
    <img class="user" [src]="user?.imgUser | safeHtml" alt="avatar"/>

SafeHtmlPipe:
    @Pipe({
        name: 'safeHtml'
    })
    export class SafeHtmlPipe implements PipeTransform {

        constructor(private sanitizer: DomSanitizer) {
        }

        transform(value: any, args?: any): any {
           return this.sanitizer.bypassSecurityTrustHtml(value);
        }

    }

component.ts: 
    this.userService.getImage(nome da imagem).then(
          (image) => {
                const imageURL = URL.createObjectURL(image);
                this.user.imgUser = URL.createObjectURL(imageURL);
          }, error => {
                console.log(error);
          }
     );

UserService: 
    getImage(nome da imagem) {
        return this.http.get(`${environment.apiUrl}/user_img/(nome da imagem)`).toPromise();
    }


The exit on the console is: inserir a descrição da imagem aqui

1 answer

0

In: Userservice: getImage(image name) { Return this.http.get(${environment.apiUrl}/user_img/(nome da imagem)).toPromysis(); }

Change the crase accent signal to simple spas.

  • I’m trying to concatenate a string with variables, I don’t know how this can help but I’ll try

  • as I said, the route is not found because I am concatenating as shown in this print link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.