N
N
n-72017-05-01 15:58:38
JavaScript
n-7, 2017-05-01 15:58:38

Angular how to save an image and then display it correctly?

I am writing a music library with the ability to add, delete and update albums. with all points well, except for adding the logo of the album. My data is stored in a JSON file.
The question is, how can I save the logo and display it correctly after an update or addition? Is it possible to do this through JSON, and if not, how? Or at least in which direction to google?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
furrya_black, 2017-05-01
@furrya_black

I do this, I have restapi.domain.dev on my web server, in my case it's nginx, a web client on another web server, also nginx that proxies requests like myapp.dev/api to restapi.domain.dev, and there I separately prescribe fallbacks for specific groups of files to restapi.domain.dev, including images.
That is, in json we give a relative path to the image, for example /assets/file.png, in the html file of the web application we write a tag with href myapp.dev/ in the head base, you can do it manually or with the help of angular.
As a result, the src to the picture will be myapp.dev/assets/file.png, when building the dom, the browser pulls all the statics, including file.png.
Requests go to the proxy nginx server on which the web app is running, it will call the fallback file extension, in which we redirect the request from our proxy nginx to restapi.domain.dev.
The problem with CORS is also solved, with cross-domain requests, we simply do not have them.
Access to files can be differentiated at the level of nginx servers.
It should be noted that if you use some kind of ready-made template for angular, built on wepbak, where, in addition to tests and yarn build, there is a yarn dev command that raises the nodejs server - expressjs for example - to localhost:port, then for it you need to configure it to proxy requests to restapi.domain.dev, otherwise everything will break in dev mode.

V
Vladimir, 2017-05-02
@Casufi

You can display it before transferring it to the server and even save it in JSON
https://developer.mozilla.org/en-US/docs/Web/HTTP/...
But there is one thing, storing files in the database is not a good idea, perhaps it is better to store paths in to files?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question