Re: Image store using Servlet
in message <1162820066.409528.11010@h54g2000cwb.googlegroups.com>, Nike
('nike83@gmail.com') wrote:
How can i store image file (jpg , gif) in database MySQL via servlets ?
As an example:
/**
* Add or edit a picture in the database.
*
* @author Simon Brooke
* @version $Revision: 1.5.2.1 $ This revision: $Author: simon_brooke $
*/
public class Picture extends ArticleAuxForm
{
//~ Static fields/initializers ------------------------------------
/** fields in my table: the article field */
public static final String ARTICLEFN = Article.KEYFN;
/** fields in my table: the author field */
public static final String AUTHORFN = "author";
/** fields in my table: the key field field */
public static final String KEYFN = "Picture";
/** fields in my table: the caption field */
public static final String CAPTIONFN = "caption";
/** the names of fields in my table: the URL field */
public static final String URLFN = "url";
/** the name of my table */
public static final String TABLENAME = "PICTURE";
//~ Methods -------------------------------------------------------
/**
* set up widgets to edit each of my fields
*/
public void init( Context config ) throws InitialisationException
{
table = TABLENAME; // my table
keyField = KEYFN; // its primary key
Widget w =
addWidget( new SimpleDataMenuWidget( ARTICLEFN, "Article",
"The article this picture is assigned to", "ARTICLE",
"Article", "Title", false ) );
w.setMandatory( "You must supply an article for this picture." );
ImageFileMaybeUploadWidget fw =
new ImageFileMaybeUploadWidget( URLFN, "Picture", "The picture." );
fw.setMandatory( "You must supply a picture." );
fw.setSize( 128 );
fw.valueType = FileMaybeUploadWidget.VALUE_IS_URL;
addWidget( fw );
w = new Widget( CAPTIONFN, "Caption", "The caption for the picture" );
w.setMandatory( "You must supply a caption for this picture." );
w.setSize( 128 );
addWidget( w );
w = new SimpleDataMenuWidget( AUTHORFN, "Artist/Photographer",
"The person who created this picture", "ACTOR", "Actor",
"Name", false );
w.setSize( 8 );
addWidget( w );
super.init( config ); // do my superclass configuration
}
}
This is using the Jacquard toolkit, from here:
http://www.weft.co.uk/library/jacquard/
The class above is part of the PRES content management system, from here:
http://www.weft.co.uk/products/PRES/
Disclosure: I wrote both.
--
simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; This email may contain confidential or otherwise privileged
;; information, though, quite frankly, if you're not the intended
;; recipient and you've got nothing better to do than read other
;; folks' emails then I'm glad to have brightened up your sad little
;; life a tiny bit.