How to show Image from local drive in Angular JS [duplicate] - angularjs

I'm trying to retrieve a picture from my file system after a good storage,(instead of putting it in the database I copy it to the disc and i put the path to the db)
I had store the picture to c:\images\ folder and supposing that the name the complete path is c:\images\mypic.jpg
when I try to retrieve it a set the img src attribute to <img src="c:\images\mypic.jps"> by using some java code
in the browser console I found this error Not allowed to load local resource: file:///C://images//mypic.jpg
Question: how to fix these path problem ? where Should I store the pictures ? and from where should I retrieve them ?

sending tag <img src="c:\images\mypic.jpg"> would cause user browser to access image from his filesystem.
if you have to store images in folder located in c:\images i would suggest to create an servlet like images.jsp, that as a parameter takes name of a file, then sets servlet response content to an image/jpg and then loads bytes of image from server location and put it to a response.
But what you use to create your application? is it pure servlet? Spring? JSF?
Here you can find some info about, how to do it.

In Chrome, you are supposed to be able to allow this capability with a runtime flag --allow-file-access-from-files
However, it looks like there is a problem with current versions of Chrome (37, 38) where this doesn't work unless you also pass the runtime flag --disable-web-security
That's an unacceptable solution, except perhaps as a short-term workaround, but it has been identified as an issue:
https://code.google.com/p/chromium/issues/detail?id=379206

You have Two alternatives :
First one is to create a ServletImageLoader that would take as a parameter an identifier of your image (the path of the image or a hash) that you will use inside the Servlet to handle your image, and it will print to the response stream the loaded image from the server.
Second one is to create a folder inside your application's ROOT folder and just save the relative path to your images.

Many browsers have changed their security policies to no longer allow reading data directly from file shares or even local resources. You need to either place the files somewhere that your tomcat instance can serve them up and put a "regular" http url in the html you generate. This can be accomplished by either providing a servlet which reads and provides the file putting the file into a directory where tomcat will serve it up as "static" content.

The concept of http location and disk location is different. What you need to do is:
for uploaded file summer.jpg
move that under a known (to the application) location to disk, e.g c:\images\summer.jpg
insert into db record representing the image with text summer.jpg
to display it use plain <img src="images/summer.jpg" />
you need something (e.g apache) that will serve c:\images\ under your application's /images. If you cannot do this then in step #2 you need to save somewhere under your web root, e.g c:\my-applications\demo-app\build\images

This error means you can not directly load data from file system because there are security issues behind this. The only solution that I know is create a web service to serve load files.

Here is a simple expressjs solution if you just want to run this app locally and security is not a concern:
On your server.js or app.js file, add the following:
app.use('/local-files', express.static('/'));
That will serve your ENTIRE root directory under /local-files. Needless to say this is a really bad idea if you're planning to deploy this app anywhere other than your local machine.
Now, you can simply do:
<img src="/local-files/images/mypic.jps"/>
note: I'm running macOS. If you're using Windows you may have to search and remove 'C:\' from the path string

Do not use ABSOLUTE PATH to refer to the name of the image for example: C:/xamp/www/Archivos/images/templatemo_image_02_opt_20160401-1244.jpg. You must use the reference to its location within webserver. For example using ../../Archivos/images/templatemo_image_02_opt_20160401-1244.jpg depending on where your process is running.

Related

How can i load and display files (such as images, videos and pdf documents) in Google Chrome v.73 from LAN

I'm building a web application that is supposed to take files from wherever in the LAN and display the content of those files. The application also uses a javascript library for generating embed objects to preview the files, if they are pdf.
The problem is that i can not successfully seem to link to those files, be them images, documents or videos.
The url is either formatted by Google Chrome by prefixing it with the address to the local web page, or interprets it as a local file and denies access to load it, or throws a connection time out if i manually prefix the file urls with http://lan-server....
As I said i tried formatting the urls to these files (the ones on the lan machines) in different ways, but none of them work.
Here is an example of an to a file in LAN
http://is-something/Subfolder/test/image.png
This one gives a timeout error
Here is another one
\\is-something/Subfolder/test/image.png
This one is prefixed with the address of the current webpage (http://localhost...)
I also tried using file:// way to access the files but it seems this only works for the local machine
So what i would want is a way to acces the files that i spoke about.
I need to use them in html elements for the src attribute, as well as in the css rules (for background url).

SocialEngine staticBaseUrl is not working in production mode

I am using socialengine as content management system, when i change the socialengine site to production mode it did not load the css file, I figured out that my $staticBaseUrl function is not returning the website name.
I manually added the path in default layout to load the css file, it works but a font family (centurygothic) is not loads. I am using SocialEngine's 4.2.4 version, please help.
I am using plesk panel for as hosting server.
If you use paths in your css file (theme_name/main.css or Modulename/externals/styles/main.css), you can use following way of indicating path:
~/application/..., where ~ will be automatically parsed and replaced by staticbaseurl.
Firstly no need to manually adjust the $staticBaseUrl in the layout. There is a setting in the admin panel (general settings) where you just specify what the URL is. This is commonly used to set the CDN URL.
Secondly, most of the CSS files in production get minimized and appended to each other, so you will only see one query similar to this: /application/css.php?request=application/themes/default/theme.css
Thirdly, if there is still an issue there may be a number of reasons. For example, are you using the http://example.com/home or http://example.com/index.php/home URL format?

Placing and accessing images outside app/webroot at Cakephp

I am currently saving uploaded images at /cakephp/uploads/ instead of doing it inside /cakephp/app/webroot/imgs/.
When i try to access the image by URL, with something like this:
http://myweb.com/cakephp/uploads/imageName.jpg
It shows a 404 error. I guess, due to the .htaccess, or more concretely, to the web.config file that i use under windows with ISS7.
Is there any way to access to them without modifying the web.config file?
Thanks.
it is my understanding that anything not placed in the webroot folder cannot be accessed directly via a url. To access files outside of the webroot, you can use Media Views.
I'd just put your uploads folder inside your APP folder, http://myweb.com/cakephp/app/uploads
then just adjust path to path => APP . 'uploads' . DS
It's not clear why you want to do this; if you want to just access the images like normal, place the uploads in to your img directory.
Typically you'd use this approach for serving files etc, allowing user authentication and so on.

Getting images with HTTP Request in C

I am writing a program in C that acts like a proxy server in a Linux system: Client asks it for a web page,
it sends an HTTP GET Request to a distant server, and it gets the servers response (web page), which is saved in an .html file.
Here goes my problem: Most web sites got some references to images, so when i try to view the .html file proxy created, the images don't appear.
I have searched a lot, but found nothing..Is there a way to write some code to GET images too?
Thank you in advance
You're going to have to write code that parses the HTML file you get back and looks for image references (img tags), then queries the server for those image files. This is what web browsers are doing under the hood.
You have an additional problem though which is that the image references in the HTML file are to the original server. I'm assuming that since they don't load for you the server that returned the original HTML isn't available. In that case after you get each image file you will need to give it a name on the local filesystem and then alter the reference in the HTML (programmatically) to point to your new local image name.
So for example:
<img src='http://example.com/image1.png'>
would become
<img src='localImage1.png'>
If you're querying arbitrary websites then you'll also find that there are various other files you'll need to do the same with like CSS files and JavaScript files. In general its hard to mirror arbitrary web pages accurately - browsers have complex object models they use to interpret web pages because they have to deal with things like CSS and Javascript and you may need to be able to 'run' all that dynamic code to even be sure what files to download from the server (e.g. JavaScript including other JavaScript etc).

alias/ short form of address of silverlight app on hosting

I host my Silverlight app in commercial hosting, but to get it I must put in address field in browser all physical path to aspx file ;/
http://netmajor.home.pl/SecretaryAppNav.Web/SecretaryAppNavTestPage.aspx
It is some way to configure application that I can write short address of my page ?
If netmajor.home.pl is under your control, you could simply move a copy of the SecretaryAppNavTestPage.aspx page to the root of your website and rename it to something simpler.
Then you could access it via http://netmajor.home.pl/SL.aspx or whatever you want to call it.
There is no code behind for that page (or you could use the matching .html test page that you will also find in your project).
If you were to make it your default page (index.aspx or default.aspx) you could just use http://netmajor.home.pl/
Hope this helps.

Resources