This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Uploading images  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a form through which I allow user to upload an image. Can somebody help me as to how a servlet should recieve this image and store in the server ? I will be thankful if somebody can explain it through some sample code. This is very vital for a project I am doing.
Thanks in advance,
Milind.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Milind,
Go to www.oreilly.com.Search for ServletProgramming by Jason Hunter.Download the package com.oreilly.servlet. On that package
there is a class called MultiPartRequest by which you can upload
any file to the server.
The image file will be uploaded just by calling the constructor.

There are two overloaded constructors
1)MultipartRequest(ServletRequest request,
String saveDirectory,
int maxPostSize)
a)maxPostSize--- refers to file size(In your case it's image size)
b)save directory -- refers to directory shared in the server to which you want to upload
2)MultipartRequest(ServletRequest request,
String saveDirectory)
If you use the second constructor you can upload only to 1MB.
But if you use the first one You can upload upto 1GB by specifying image size in bytes.
Note:
specify in the form tag parameter as
enctype="multipart/form-data" .So that it handles MultiPart Request
Regards
Lala
------------------
Lala
 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the response. I will try it now.
Milind.
 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am very sorry to ask this silly question. I am unable to download com.oreilly.servlet package. Can somebody tell me how exactly to do it ?
Thanks a lot.
Milind
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am wondering what programming language are you using in your application. I only know how to do that by using ASP (active server pages). If you want to know more write me back.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!