play! Uploaded images not visible in production mode - java

Hi guys I'm new to play framework,
Qun 1:
what I wanted in my server is Users can upload images, and see uploaded images in web page,
when I run the server in Dev mode everything is works fine (I can upload and see the images in web page),
but I try do this same thing in production mode, uploading works fine(images saved in public directory) but images are not visible in web page...!
my twirl html template:
<img src="#routes.Assets.versioned(public/file1.png)" width=25% height=auto alt="file1.png">
routes:
GET /versionedAssets/*file controllers.Assets.versioned(path="/public", file: Asset)
browser's Elements page (F12):
<img src="/versionedAssets/file1.png" width="25%" height="auto" alt="file1.png">
I can even show the image using NGINX (passing image location as an url) successfully,
but why i can't see the image in play's production mode?,
I don't even have clue about what part I did wrong.!
please help me if you know anything about it.!
Qun 2:
Is that possible to serve our app without frontend server like NGINX, etc.
because play already running in AkkaHttpServer.

After reading docs
I've found Ok.SendFile() method used to serving files, then I've created a method in controller
def getImageFromPath()= Action{ implicit request: Request[AnyContent] =>
Ok.sendFile(new java.io.File("/path/to/file")) }
then added route in routes file
GET /getimage controllers.ImageController.getImageFromPath()
reverse routing in Twirl template
<img src="#routes.ImageController.getImageFromPath()" width=25% height=auto alt="file1.png">
helped me to solve this issue..!

Related

SAP Hybris email velocity template image reference

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

GWT link to JSP page fails when deployed to App Engine

I have been linking my GWT app to a page written with JSP, for multifile uploading.
The gwt code to open the upload page in a new tab is:
Window.open("/secure/newuploads", "_blank", "");
This works fine in dev mode but I deployed to App Engine today and
the link doesn't work: the displayed page is blank, no error code.
My JSP and JS files are located in \war. Any ideas?
Assuming layout of war is like
-> webapps
-> sample
-> gwtsample
-> jsp
-> images
-> css
You should use GWT.getHostPageBaseURL() to get to the root of the sample app and then move to relative jsp file. Reference image below to distinguish between module base url and hostpage url.
The problem disappeared if the redirect servlet uses
HttpServlet.doPost() & doGet() not service()
In dev mode I was calling service()
with tests
if(req.getMethod()=="GET")
or
if(req.getMethod()=="POST")
On google's servers these don't work:
You have to give the full path there. Change to:
Window.open(GWT.getModuleBaseURL() + "secure/newuploads", "_blank", "");
Go through once :Getting URL's of my page ,API.
For more description about the issue you are facing refer this discussion too.

java servlets display image in html code

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.

java tomcat links generated don't work

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.

Need to get a path location via a web page

In firefox 2 I was able to get the path using Browse - I use the path in our project to then write out files to that location. So now that browse does not get the path, does anyone know a way for a user to go to a directory and have the path returned via a web page so I could pass that along to the server for processing?
execCommand does not work in firefox and had limites save type capaility, and entering by hand is not a useable option. Thanks.
The ability to see a complete client file path is now considered a security risk, and all modern browsers prevent you from seeing it (both via Javascript and via information sent back to the server on the form POST).
This is not possible with HTML/JavaScript. In HTML you can at highest use <input type="file"> to select a file, but not a folder or so. In JS you can't do anything at the local disk file system, let alone with a <input type="file"> element in the DOM tree. You're prohibited by security restrictions (you as being an enduser would of course not like if websites are able to do stuff at the local disk file system unaskingly).
You can only do that with a small application which runs straight at the client machine. For example a (signed!) applet which is basically just a piece of Java code served by a webpage which runs right at the client machine. You can communicate between applet and servlet using java.net.URL and consorts. Then, in the applet use Swing's JFileChooser to have a folder or file selection dialogue.
Update: by the way, MSIE and some other ancient browsers sends the full client-side disk file system path along the <input type="file"> to the server side. This is technically wrong (only the filename+extension should have been sent) and completely superfluous. This information is worthless in the server side, because it cannot access the file using the normal java.io.File stuff (unless both the server and the client runs at physically the same machine which of course wouldn't occur in real world). The normal way to get the uploaded file is to parse the multipart/form-data request body (for which one would normally use Apache Commons FileUpload or the Servlet 3.0 provided HttpServletRequest#getParts()).

Categories