How to get the assets controller in Play to detect new images? - java

It seems that if you have play running in production mode, and any new images are added to the public/images directory, the Assets.at() method does not detect these new images until Play has been stopped and restarted from the console.
Is there any way to force the Assets controller to refresh/recompile the list of assets while in production mode? Or do I have to write my own controller for serving up images? (If so, is there one already written to do this that I can reuse?)

You will have to write your own action for your uploaded pictures.
The Assets controller is a controller that serves static resources which are bundled within your application.
You can find a very simple (and low tech) example of an action for retrieving a picture here (I think you'll get the idea).

Related

Make videos playable just in my app

I'm making an app which contents should be downloaded from a server. After downloading videos, I want to prevent them from publishing or sharing. I searched about this and find out that putting a dot (.) before the name of the video will hide it from file manager and gallery. But if the user uses a professional file manager would see the videos!
I want a solution to make videos unplayable via other apps.
As far as I Know, you could put your files in your internal directory which is private and only your app can access it.
but still, devices with root access can view and edit your files.
you can get private file location via context.getFilesDir()
You can use cache directory instead of External storage
Ex:
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
each app has own cached directory and can accessible only for that app (unless root)
That one simple way to hide media from other apps
more

Java web application need to refresh to "see" resource files

I'm working on a web based application with Spring MVC and Thymeleaf. I have form which upload image. I decided to save the images in src/main/resources/static/images/ and that works perfect. But I found an issue with upload. When I save new image and try to display it in the HTML it's now working. When i refresh the images folder from STS and refresh the page it works fine. Can you give me some advice why this is happening and is there a way to fix it? I know i can use java code to get image content and display it as a resource but i would like to use thymeleaf's EL. I display the image with #{/images/imagename.jpg}
Best regards,
Peter
The thing is, if your resources are within your web app, you won't be able to display it and change it at will. When you refresh your images folder on STS, it "redeploys" the resources and you can see your images.
What you need to do is to put your static/images folder outside your web app, then you'll be able to easily upload a new image and have it displayed on your web app

Uploading images to a specific place in a Java web server

I'm working on a Java web application. As part of this web app, I have a database containing objects with image file paths associated with them. By simply dragging and dropping, I was able to put these images in an images folder in my web server. Their path in Eclipse appears to be src/main/webapp/images.
When I want to access these images in a JSP page, I simply make an img tag with src="/images/fileName.png" and it works perfectly fine.
Here's the issue. I want users to be able to upload their own images to the web server, storing the filenames in the database. I've been looking around for a way to do this, but I'm having trouble finding a detailed answer. What can I use to write the images to that specific folder, images, in my web server? Thanks in advance.
For reference, here is an example of a fileName: /images/propane.png
And here is an example of me calling it in JSP: <img src="/images/propane.png">
I realize this may be a kind of basic question, but I'm really having trouble with getting the image to be stored in that specific directory.
You need to be aware that anything uploaded to src/main/webapp/images will be deleted when you deploy a new version of your application to OpenShift. You can save and serve the images from the OPENSHIFT_DATA_DIR, which is the only directory you can write to that won't be deleted when you redeploy your application. You also need to be aware that the files in OPENSHIFT_DATA_DIR are not shared across gears in a scaled OpenShift application. So if your application is scaled, you need to store user uploaded images somewhere like Dropbox or Amazon S3.
For details on how to serve images from OPENSHIFT_DATA_DIR via your Java application, look at the answer to this question and this OpenShift tutorial.

Java Webapp - Where to store Images

I created a web application using Java Spring, Hibernate, with JSP's. It's basically a blog I made from scratch, so there's an interface where I can add a new blog post with pictures.
I use Heroku to host and deploy the app.
When I want to post images in a blog post, I do:
And that image is currently stored in a resource folder right outside of 'WEB-INF'. Except, as I add more blog posts, I will have a lot of large sized pictures. I don't know where I should store these images and how I should access it. I thought of storing it in the file system, but wouldn't I have to re-deploy the app on heroku each time I add more images? Another option was having a public dropbox folder and linking the images there, but that would open up my entire dropbox directory to the public. Is there a better way to do all of this, especially managing so many large pictures?
Saving files in file system is not a scalable solution. If you add new servers for your web app the images won't be displayed correctly for any request.
You have to save your images in a distributed environment. It can be a LOB column on the database (Postgres for example) or an Amazon S3 storage system.
The access type is very different but both systems are a good option for your images. If they are big in size, S3 is the best option.

How can I convert one slide of a PowerPoint file to flash in jsf app (using javaSE/javaEE)?

I need to show the first slide of a PowerPoint presentation in my jsf app. It must look something like that:
user upload the .ppt file to jsf app
the app take the first slide and converts it to Flash
user sees the converted slide in the separate (not as part of the another page)
I suppose that I couldn't use any external converters because the user of the system will not have them when he uses our system.
Also I'm thinkinig about Flash, not HTML, because the presentation can be dynamic.
Any ideas? Can I do this task or it's impossible and I need to think in another way (maybe restriction for end users - to save presentation as png, but I think that my boss won't like this decision).
Maybe I need to look at .xslt format, maybe it would help?
suppose that I couldn't use any external converters because the user of the system will not have them when he uses our system.
You can truly use external tools since your Java/JSF code runs at the webserver, not at the webclient (webbrowser). All the webbrowser get is just the Java/JSF-generated HTML/CSS/JS code. Open a page in webbrowser, rightclick and View Source and see it yourself. You just install the external tool at the webserver and execute it there.
To upload a file in JSF, you'll need to grab a 3rd party component library since the standard implementation doesn't have an upload component, for example Tomahawk's t:inputFileUpload or the one of whatever component library you're currently already using.
To convert PPT to Flash, execute the appropriate action using external tool in the managed bean action method and store the Flash file somewhere in the local disk file system of the webserver. You can store it in the public webcontent so that it's directly accessible by URL, but those files will be lost whenever you redeploy the webapp. If this shouldn't happen, then store it outside the public webcontent.
I don't have hands on experience with PPT-Flash converters, so I can't recommend a specific one, but Google learns me that there's pretty a lot of choice. There seems to be a Java solution of iSpring.
To display the Flash file, use the HTML <object> element which points to the URL of the Flash file. If the Flash file is stored outside the public webcontent, then you'll need to create a Servlet which gets an InputStream of the file from the local disk file system and writes it to the OutputStream of the response along a correct set of HTTP headers and then let the URL of the <object> element point to that instead.

Categories