I am sending image to a Servlet using html form. I am getting only filename but wants the full path of the image. Second, i want to store this image in web application images folder.
I am getting only filename but wants the full path of the image
For security reasons it is impossible to get the full path to the image on the client computer. This information is never sent to the server.
As far as the second part of your question is concerned about storing the uploaded image on the server, there are many articles out there illustrating this.
Related
I got a web application with a Java backend and React frontend. It allows users to upload and display pictures like in an album setting.
The application fetches data from a MS SQL server containing data about an image and then displays it in react.
The database contains a table with information about the image (filename, extension etc.) but not a BLOB.
I am currently displaying the image in react by creating an url from my local machine.
My question is now, what file system alternatives is there when i want to stop storing the images locally on my windows machine. Is it possible to use Google Drive API or something similar? What about SFTP? Would appreciate free solutions to begin with.
You can use Amazon S3 to store your images. store information about the image like file name, bucket name ,... etc in your database and store the image itself in Amazon S3.
There are also other alternatives to Amazon S3 if you want, like MinIO, which is open source and S3 compatible.
I have downloaded an image from a URL using ImageIO.write, so now I am wondering if there was a possibility of somehow caching that image. Is there a possibility to compare the downloaded image with the URL it's downloaded from to know that the image is from that URL? I need this because if I download an image and than later call that same URL for downloading, my app can recognize that it already has the image downloaded, so it doesn't download it again.
You should try to see if you can integrate the code to upload the picture to google and search by image. Or, you can also save the url of the image with an array while storing the image if you have multiple images you want to download at once.
I need to upload images and i want to show all of images in another page. I have tried to use volley, but it need to encode and decode to show all images. It made my application not responding when i decode all the string of images.
My questions are:
Are there any ways to upload images beside volley?
Are there any ways to upload images using volley without convert them to string (encode)?
Thanks
I implemented it once by positing multi part file using HttpUrlConnection.
Basically you provide the image file input stream, the desired file name and the file's MIME type.
You can access the source code through this link:
https://github.com/MinaSamy/DailySelfie/blob/master/app/src/main/java/bloodstone/dailyselfie/android/utils/PostMultiPart.java
I've googled for some efficient image storage solutions and got very exciting line to read that you should store only image path rather that whole image in the database.
Now I am working on a Java web project based on MVC and is willing too know extra about this topic. Specifically I want to know if I am able to save my image directly to any image hosting website from my Servlet which instantly provide me a link that I will store in my database column for future use?
you should store only image path rather that whole image in the database.
That's indeed recommended. Storing binary data in a database makes semantically no utter sense. You cannot index it, nor search in it, etcetera. It's just "dead" data. You can store it as good directly on the disk file system and then store its unique identifier (usually just the filename) in the database. The filename can be a varchar which is indexable (which thus allows for faster SELECT ... WHERE).
I want to know if I am able to save my image directly to any image hosting website from my Servlet which instantly provide me a link that I will store in my database column for future use?
I'm not sure what's your concrete problem here. You should realize that transferring bytes is after all just a matter of reading an arbitrary InputStream and writing it to an arbitratry OutputStream. Your concrete question should rather be, "How do I get an InputStream of the uploaded image?", or "How do I get an OutputStream to the local disk file system?", or maybe "How do I get an OutputStream to the image hosting website?".
Getting the uploaded image's InputStream is easy. All decent file upload APIs offer kind of a getInputStream() method. See also How to upload files to server using JSP/Servlet? Getting an OutputStream to a File on the local disk file system is also easy. Just construct a FileOutputStream around it.
File file = File.createTempFile(prefix, suffix, "/path/to/uploads");
InputStream input = uploadedFile.getInputStream();
OutputStream output = new FileOutputStream(file);
// Now write input to output.
String uniqueFileName = file.getName();
// Now store filename in DB.
Getting an OutputStream to some other host is a story apart. How do you want to connect to it? Using FTP? Use FTPClient#appendFileStream(). Or using HTTP (eek)? Use URLConnection#getOutputStream() or HttpClient. You should ask a more finer grained question about that if you stucks.
Finally, in order to get this image by URL (by either <img src> or direct request or whatever), read this answer: Reliable data serving.
Here's a tutorial how to upload a file to a server using servlets/JSP. Then use Apache Commons IO to save it to some directory on the server. Save file's path in the database and use it next time this file is asked for.
Sure, you can use apache commons api to upload your image to specified folder in server, and you can change its name as you wish, what ever it may be the image format you can save the path in Database and upload the image using servlet. apache commons api is for free, you will get the proper documentation apache site.
How to retrieve all images from a site. I want to make desktop application which show images of a cars received by a web site.
You will need to do is get the HTML from the site you're connecting to and search for all the <img> tags, parse the url out of them, and then loop through each url, connect to it, download the image, then use your app to view the images.
Google is loaded with examples how to download files from urls.