• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Uploading images

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic