I have a problem with an image upload in spring 3 mvc. I search a couple of hours but can't find any satisfying solution.
What I want to do?
I simply want to upload an Image to the server and store it in a location where I can easily access it from my jsp sites to show the image and so on.
I don't know, if use the wrong keyword but I can't find a good solution for it and I'm to new on spring to figure it out by my self ...
So the problem is not to store the file on the server, that problem I solved already but till now I can only save it to the ServletContext#getRealPath() and there I think I can't access the image in the jsp site.
Did have anyone a good idea how I can solve that or any hints to find a solution ?
very thanks for your help and very sorry for my english ... it is quite late in germany -.-
According to me when you try to access the image in your jsp file it will give you 404 error.
You need to include the following line of code in your servlet.xml file.
<mvc:resources location="/assets/" mapping="/assets/**" />
You just need to replace the path you have stored your uploaded images in. And then everything will work.
Hope this helps you.
Cheers.
thx for your help, my problem is how to get this path for saving my file to it.
here is a code snippet how I do it now (I found this way in several tuts, but i do not know, if this is a good way to save images)
ServletContext context = RequestContextUtils.getWebApplicationContext(request).getServletContext();
try {
if(!image.isEmpty()) {
validateImage(image);
sizeChart.setImgPath(saveImage(context.getRealPath("/") + "/images/" + image.getOriginalFilename(), image));
}
Related
I'm working on a web project and I am required to write some functionality that will
allow a user to upload images/videos, then display them. The problem is that when I start doing some research for how to accomplish that task, I hear a lot of people saying that I should not
save the images in my database, but rather to an external server then just upload the file path
in the form of a string to the database.
Now this concept is completely new to me so I don't even know where to look or how to start. I am
programming in Java and I am using springboot, and hibernate. Could someone please point me in the
correct direction, as I have been googling for hours and I have found nothing that shows me how to
accomplish this.
Thank you very much.
I have a link for OneDrive. The format is https://onedrive.live.com/?cid=XXXXXXXXXXXXXXXX&id=XXXXXXXXXXXXXXXX%XXXXX
The link is public, it's not mine and new files is often added in it. My question is simple. What is the best way in Java to list all the file/folder from this link and to download a file ?
I tried HtmlUnit but it give a big javascript error.
Since the link is public, do I really need to use a OneDrive SDK ? I really don't know how to proccess with OneDrive... Thank's for any help
https://github.com/isac322/OneDrive-SDK-java This SDK will help you get the path and download the folder.
I've been at this for 20 minutes now and I just can't wrap my head around where I'm going wrong.
If an image is in the same src folder as a java file, why doesn't this work:
Image image = ImageIO.read(getClass().getResource("/image.png"));
I'm not sure if I'm missing a trick or something but I've only been able to load image from http URLs which isn't very helpful for my project.
I know this is a silly question but I've looked at many other answers with similar titles but very different problems. There was also another answer that didn't work at all.
I feel like an idiot posting this but I'm honestly about to upload all my resources to a cloud service instead of having to deal with this.
after this interesting discussion , we found that the image file was corrupted and that is why it was not reading (parsing) it to BufferedImage properly
it should be in the same folder as your .class file not .java file! and furthermore you as others commented you should remove / from image address
I am working on a project named as LMS (Learning management system) and the modules allocated to me are:-
The uploaded course content saved as ppt,doc ,pdf or audio/video file should be opened in the same window.The application by which file needs to be opened should be embedded in the context window itself.
The uploaded course content saved as ppt,doc ,pdf file can be converted to audio/video file.
I have to code them in JSP.
Being new to java i am not getting how to do these. Can you plz plz help me out by showing me some direction? I shall be very thankful to you.
I will be waiting for your reply desperately.
Thanks and regards
swati
First I have to ask do you already have a transformation server/code to do the conversion in point nbr2 or do you ask for guidance on that to? If that's the case maybe you can look into HTML5 for this otherwise use something like flash.
I would say use HTML5 for video and the other things I would require the users to install the correct plug in adobe reader ... I think it's reasonable to put requirements on the user when using an enterprise app.
Almost all of this could be done in HTML JavaScript inside your jsp.
Hai,
I am using Java GWT. In this i want to load one html file.
htmlPane.setContentsURL("http://www.chellasoftapp.com/ATBrowser/images/disclaimer.html");
htmlPane.setContentsURL("images/disclaimer.html");
Which one be the faster? How is it works?
In images folder of WAR I placed that html file. Is it correct place? Or Where can i upload this?
Give suggestion for this issue.
Thanks in advance.
Regards,
Sathya.A
This solution:
htmlPane.setContentsURL("http://www.chellasoftapp.com/ATBrowser/images/disclaimer.html");
has quite big disadventage. It doesn't work in development on local machine.
I would use
htmlPane.setContentsURL(GWT.getModuleBaseURL() + "/images/disclaimer.html");
This one always works, doesn't matter if your application is at http://www.chellasoftapp.com/ATBrowser/ or at URL root: http://www.chellasoftapp.com/
Can you put .html file into images directory? Yes you can, and technically it is still valid, however, it is not readable and not obvious. I.e. it is hard to understand for other developers.