Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Uploading images

 
Milind Mahajan
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.
 
Lala Viswanath
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
 
Mindy Wu
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic