• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Help With File Upload

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is below. I need some serious help with this issue I am having. Any help will be 'very' appreciated. Can you please provide me a solution to my problem. Thank you so much you guys.

CURRENT SCENARIO:

- File of my choosing does upload just fine.
- Lists File size.


THE ISSUE:

- I can't figure out how to get the file I uploaded to a specific location on my PC. As of now, I have no idea where it is uploading to. This is my main concern and I need to have it turned into my boss in the AM.
- I am also having an issue getting the "file name" to print out as well.



UploadFileControler.java



UploadFileIndexController.java



UploadFile.jsp




UploadFileIndex.jsp

 
Marshal
Posts: 26115
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why your upload controller has a "setUploadFolderPath" method. I don't see it being called anywhere in your code, but perhaps it's being called when the servlet is created, from some configuration entry or something like that. You should check into that.

And supposing that part is working, then you should actually be using that folder name in the code which you put your question comments next to. Using "request.realPath()" is wrong because you shouldn't be storing files in the application's context. And as for why "/images/" is there, you'd have to ask the person who wrote that code why they wanted to hard-code that part of the file path.
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip. I tried that but I erased it because I could not get it right so I just left it as was and posted it on here. Could you give me some code showing me what you're talking about as an example or simply the solution.

Thank you very much.
 
Paul Clapham
Marshal
Posts: 26115
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Or something like that. You still didn't say whether the setUploadFolderPath method was being called and, if so, whether it was being called with a sensible value.
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That method is not being called. I initialized the value to the directory path I would like the file to be stored. The only thing is, I tried exactly what you just said before I posted this and that is what I deleted to put things back the way the were before I posted this. That did not work.

Any other potential solutions?
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could have put it in the wrong place though. Should I delete something and use that line of code to take its place or simply where do you believe I should place this in my code?

getRealPath() is a method that is in my code currently and it states it is deprecated... Is there any method that does the same thing you know of? This is a separate question keep in mind.
 
Paul Clapham
Marshal
Posts: 26115
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it looks like this is one of those roseindia examples so it isn't surprising that it isn't up to scratch.

If you need to get something working then just pick a directory where you want the uploads to go to and hard-code that directory path at the place where you had the comments. As for getRealPath(), it's deprecated because you shouldn't be doing that. And therefore you shouldn't be looking for other ways of doing that.
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that I believe before I changed it back to the way it was.
It didn't work the way I did it.
Could you please provide me an example of what you mean exactly?
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and exactly where to place it.
 
Paul Clapham
Marshal
Posts: 26115
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I can't. In my opinion you should be doing at least some of the work here. My part of the work is done now until you come back with something substantive.
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you just don't know how? The reason I posted this to begin with was for examples. If you are going to give me a suggestion, tell me how to use it. If you don't know, don't leave a response. It helps others understand the issue at hand and is the point of the forum.
I already told you that I did exactly what your advice was and it did not work. I am asking if you know how to use your advice because the way I did did not work. Your sarcasm is not necessary sir, your responses help not only the person posting but others as well. If you can't follow through with your examples, this forum isn't for you.

 
Paul Clapham
Marshal
Posts: 26115
77
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy, I have implemented file uploads. My impression from your posts so far is that you have got some code from the internet which you do not understand at all, and that you are trying to persuade other people to change it for you so that you can then pass the result off as your own work. I don't want to be one of those people.

However that's just my impression. I could be wrong. And you could prove me wrong by demonstrating some slight amount of comprehension, as I have already suggested. So instead of trying to imply that it's my fault because I haven't given you the answer, you could post the code you have so far and explain what your problem is now. I would also suggest that you read some of our FAQ entries like DoYourOwnHomework and ItDoesntWorkIsUseless.
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if you mistook me as being rude back to you. I wanted to clarify that with you.
Also, I am not passing this really bad code off to anyone. This is solely a practice project as I am 100% brand new to Spring and haven't worked a whole lot with IO anyway. So you are sort of wrong, and I don't know how to continue with what I want it to do. (Below is an example of what I did to the code before your advice and before I changed it back to how it used to be). Just like you said, this code is from another site and I am 'only' trying to figure out how everything works together with the inclusion of seeing how setting a directory for it to be stored in is put in place inside the controller. Everything that I have read stops at uploading the file. Nothing I have seen fully demonstrates how to do what I am trying to learn.
SO bottom line here is that I posted this here to see if someone can help me.
You posted advice that I have already tried and failed to work (probably used it the wrong way). This is the way I changed it: (and that doesn't work)


With that being said, maybe you can explain your advice to me in a little more detail? If you wouldn't mind of course.
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, just to show you my comprehension even though it is not good, here is my code that got me exactly what I wanted and I just accomplished it 5 minutes ago. Okay so now that I have this, can you point me in the right direction to get it in my database from the directory I saved it in...? Is this even possible?

 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also any advice to make the code I did better would be appreciated.
reply
    Bookmark Topic Watch Topic
  • New Topic