-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:
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();
}
I’m trying to concatenate a string with variables, I don’t know how this can help but I’ll try
– Qattus
as I said, the route is not found because I am concatenating as shown in this print link
– Qattus