Why playframework stored image attachments with no extension? - java

I didn't change the configuration , but i found the uploaded images were stored with no extension. This makes me confused when managing those images.
Is there anyone knows how to deal with this ?

You're doing it wrong. Checkout this article.
Especially the part about saving the file.
And secondly, when uploading, you're uploading files. Not images by default. And files do not have img extensions. That part has to be managed manually.

Related

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.

Does `javax.imageio.ImageIO` require file locking?

My app is saving images into a folder. Simultaneously another piece of software watches over this folder and prints pasted images.
Problem I've encountered is that printing app can send on printer half rendered image or doesn't react to saved images at all.
I'm using javax.imageio.ImageIO.write(RenderedImage im, String formatName, File output) to save BufferedImage into png format.
If locking required please provide a code example with explicit locks. If not explain why.
I've tested on Windows, JRE 1.8
Basically, you should write the image to a temporary file and then rename it to the final file name. this way the file is completely written before the other app becomes aware of it.
You probably want to implement some kind of locking mechanism that files are only read when they are completely written, or not at all.

How to create BufferedImage from bitmap data

After going through many similar looking questions I had no way but put my own question here.
I need to display an image on swing application. The source of image is bitmap data which is retrieved from MS SQL server. I have tried the following ways
TRY 1 - I have tried creating an ImageIcon from the bytes retrieved. No results.
TRY 2 - Saved the bytes in a .png file and tried loading Using ImageIO. This works fine on my local machine but fails on test server. Both are windows machines.
TRY3 - On step 2 I tried saving in different formats than .png. It does not work at all.
Please let me know what am I missing?
NOTE : I have tried including jai jars into the Referenced Libraries also.
You should have stored a hint what format the data has in the database. If not, you can only hope that ImageIO can handle it.
There is no need to write the data to files (which is a pitfall in itself, where would you write them? Think of restricted process privileges and disk quotas). Just create an InputStream that accesses the data directly (e.g. java.io.ByteArrayInputStream), that way you can have ImageIO load directly using the stream based methods.

BlazeDS/ FLEX - Upload an Image and Display

I'm working on a FLEX which enables the user navigate through a list of images at the server (BalzeDS tomcat 4.0.0.14931). The images stored under the "WebContent/Images", and the already available/ saved images are displayed as desired.
From this app user would be able to select a file from their local directory and upload it. I have done the necessary coding related with uploading the image and it successfully creates a copy at the desired folder at the server. Once the image file is uploaded I'm trying to display the it at the FLEX end, but the image is not displayed. When check at the target folder at the server end, the file has been created successfully.
In order to make the uploaded image visible, the BlazeDS Tomcat server has to be restarted. Since this is not desired way to go ahead, I am seeking some help from you experts out there to resolved this.
I tried searching the net get this issue sorted out, but unable to come cross any solution. An identical issue was posted on another forum (Tomcat restart problem), that also still not resolved.
I this is best approach to achieve this JAVA/ BlazeDS/ TomCat/ FLEX environment or is there a better alternative. The other alternative I could achieve this is through persisting the file into the database as byte[], but I did not want accomplish in that manner since size of the database tend to shoot up.
I would really appreciate if you could help me out on this.
Thanks in advance.
If you have to restart Tomcat, that means you are storing user data in your web-apps directory. You should not be storing any user data in the webapps folder. These are considered "system files" and should not be publicly editable under any circumstance.
Store any user data in a publicly accessible folder with the correct permissions and serve them over HTTP (you should be able to view it in a web browser).

How to download image from .shtml using java?

I have a problem with downloading images from web-pages using java - it all works fine except for .shtml pages. Any idea? I can get the page's source but cannot download images from it. Thanks for all opinions in advance.
The shtml extension won't effect how you download the data. It just indicates that the webpage has server side included content.
There must be something else with the webpage that is tripping your up, unrelated to the extension. What this is can't be determined from the amount of information provided.

Categories