When I try to upload image with the exmaple given in the froala java sdk, the picture is stored in local storage but the picture disappear because the server have no access to the folder.
Error here:
froala upload image error 404
Just added new context in the Tomcat file server.xml to point to the folder images in the root of the server:
<Context docBase="images" path="" reloadable="true" source="your source"/>
Then in class File.class changed parameters in method FileUtils.copyInputStreamToFile to save images in this folder.
And I should add a Thread.sleep(5000) after Image.upload() call in UploadImage.java to display image otherwise it didn't work. I think there is a problem with synchronization between the upload and the http request GET which get the image.
So I didn't succeed to create my own servlet so I used those in froala sdk examples.
I tried to find where the http request GET is made in froala's javascript, to change the URL in http request but didn't find.
Didn't understand why the froala example didn't work but find how to make it works in other way.
Related
I have .vm file for confirmation order mail and I'm placing some informations to this .vm template. There are several images in these informations. But my images not rendered while the email was sending.
I tried several methods but doesn't work.These are:
<img src='${ctx.contextPath}/images/theme/social_01.jpg
<img src='${ctx.themeResourceUrl}/images/theme/social_01.jpg
and
<img src='../images/theme/social_01.jpg
Any one of these are didn't work for me.
Also my images at the following location of the project:
xxxStore > import > sampledata > contentCatalogxxx > images > theme >
How can I solve this problem ?
Can you print the complete image URL in the email and try to open it in the new browser window and see. You should able to access your image. If not, try looking at the URL, is it correct? Let me know the result.
I would suggest you to following any exiting working image, place your image to the same folder, and access it similarly.
It seems you are trying to access static image. You can find all frontend static content under the webroot folder of the storefront extension. Your image should be in the same folder as well.
e.g.
I have an image at
sastorefront/web/webroot/_ui/responsive/theme-blue/images/test.png
I can access it using
${themeResourcePath}/images/test.png
To debug path issues, I would print the path, and try hitting same URL through the browse. Ideally, an image should be accessible with the URL. Say in my case, I can access test.png with
https://example.com/_ui/responsive/theme-blue/images/test.png
You have to make sure that your image URL which you are using in VM is corresponding to the actual image URL.
To provide this,
go to Backoffice media type
check your media URL
i am trying to save image outside of my web app directory.
i have hosted my application on shared. so i got a root folder to deploy my project. How can i just make a directory outside of my webapp so that i can upload my images on it. and if i redeploy my app then those images will not lost.
eg. i got root space and i pasted all my build folder on it. I want the upload folder not to be lost if I redeploy my app.
fileSystemPath= "/files";
try{
File destFile = new File(fileSystemPath, thempicFileName);
FileUtils.copyFile(thempic, destFile);
String path=fileSystemPath+"/"+thempicFileName;
With the above code a folder is creating in D drive(my current working directory), and in my db file is storing like /files/smg.png And if i try to access that image using <img src="/files/smg.png"/> from my jsp page then i am not geting that image to be display.
Where the project and files are exactly..
with the above code my images are saving in D:\myprojectDir\files and my project location is D:\myprojectDir\projectfolder
THIS PROJECT IS BEING DEVELOP IN STRUTS2
Please suggest me in which way i have to write the code so that i can receive my images on jsp.
You can store the image in any place accesible from your server app.
You must open the file and send the stream to the response using an especific servlet wich url you put in your jsp.
This is an example with Spring:
File file = new File(...);
Resource resource = new FileSystemResource( file );
HttpHeaders headers = new HttpHeaders();
headers.setContentType( MediaType.IMAGE_JPEG );
return new ResponseEntity<Resource>( resource, headers,
HttpStatus.OK );
Edited: You have a lot of examples searchin in Google for: "Streaming image to http response".
You can not access directly anything else that your webapp from the browser (and even there some folders are protected). Imagine the security hole that it would be if you could.
You can write a "proxy" servlet/JSP that reads a file from your filesystem and returns it back to the browser, though. You may need to ensure proper access to your tomcat user, and give it access with selinux if you are using it.
But please, don't do that without a good reason and all the checks that you are only accessing the path that you intend to (so, check that nobody is passing you a file like ../../mySecrectAccountPasswords.txt).
I've got a smartgwt application which create a link with a jpg/gif/png/pdf files. This files are shown in browser. I want to get the save dialog instead it which ask me the path when I want to save the file at local machine. How could I do that?
As I know, you have to change the response header by setting the Content-disposition to attachment. Like this:
'Content-disposition: attachment; filename=image.jpg'
'Content-type: image/jpeg'
With these the browser will understand most cases that it should show up a dialog to save the image with the name: image.jpg. Also it might offer you to send it directly to an application, for example to an image viewer.
To get it work from a simple link, perhaps you have to write a servlet which will return the requested file with the correct headers and call that servlet from every link with a parameter to the real file.
I have a servlet which returns as response an html page that also includes pictures. I have those pictures stored on the file system in the Pictures folder (path: /home/andrei/Pictures).
I currently have there just one photo(name: eu.jpg ) but i will add more.
So the point is that in the html code i somewhere have this: <img src="/home/andrei/Pictures/eu.jpg" alt="pic" > . But when i get the html page it doesnt display neither the photo nor the "pic" text from alt(not sure if this is normal...). I read that it may be due to the path i gave in src but i dont know exactly what to give.
So what path should i give to the src?
And is it normal not displaying the alt text because i knew that when it cannot load the pic it shows that text.
Additional information:
IDE : Eclipse Juno
SO : Linux
Server: Tomcat 7.0
Any image you intend to display in a browser connecting a web container (Tomcat in your case) must be visible in the container. To do it, place the images in the webapp/ folder and link them properly from the servlet generating the correct tag where path is the correct http link to your file.
When you send back the HTML response, the client's browser will render the document and then, send requests for additional resources in order to show the HTML document fully. That includes the images, so Tomcat must be able to serve them. If you can't put them in a folder inside WebContent from the beginning, the servlet must do the move and create the document specifying the "public route".
The images should be part of the webapp. Absolute FS path will not work. <img> will take relative path, or absolute path wrt the website.
I'm just doing a java tomcat project, that does some query in a database then return the file path of some web pages.
Now I have mapped my only class in web.xml and the webapp does return a list of urls which correspond to some html pages in my local disk. I set up a side frame in the webapp, my idea is that I output the results in the output page like "file:///file_path_of_html_page" and when this link is clicked, the side frame will show the html page.
But actually I got the right links but when I click on them, nothing happens, chrome tells me "Not allowed to load local resource". Even I set the target="_blank", the link doesn't work. But the "file:///filepath" are all ok when I type them in the address bar. I've moved all the html pages in the eclipse project folder but that didn't help.
Any suggestions to do this simple task?
The average browser disallows due to security reasons opening file:// resources when the parent resource is by itself served over http://. If you make them fullworthy http:// links, then it will work properly.
Even if the browser allowed it, this approach would not going to work when you publish the webapp on a different server. A file:// resource refers to the local disk file system, which is the one the client (the user with the webbrowser) is using. This is normally in a physically different machine. The client should have a copy of exactly those resources on its own local disk file system beforehand in order to get the file:// links to work.
Just put the HTML pages in public web root of your web project (there where you normally put your JSP files and so on) and use (relative) http:// links to refer the HTML pages. For example, the following link in a http://localhost:8080/contextname/some.jsp
link to some html file
would open the http://localhost:8080/contextname/some.html file.