dcsimg
Problem with image file
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bikash_paul
Posted On:   Tuesday, December 4, 2001 12:27 AM

Hi, Iam facing with one problem.I have one swing interface through which I can upload files(back end servlet programme).Now I can upload all types of file but problem with image file it uploading perfectly that means size of the uploaded file is ok but its format damaged.It can not be open.My backend servlet programme is ok coz i tested it with html form it is working perfectly.Problem with swing interface.Plz guide me where I done a mistake.Below r my codes:- ImageIcon Upload=new ImageIcon("images/Upload.gif"); Button=new JButton(Upload); Button.setToolTipText("Upload"); Button.addActionListener(new ActionListener() {    More>>

Hi,


Iam facing with one problem.I have one swing interface through which I can
upload files(back end servlet programme).Now I can upload all types of
file but problem with image file it uploading perfectly that means size of
the uploaded file is ok but its format damaged.It can not be open.My
backend servlet programme is ok coz i tested it with html form it is
working perfectly.Problem with swing interface.Plz guide me where I done a
mistake.Below r my codes:-


ImageIcon Upload=new ImageIcon("images/Upload.gif");


Button=new JButton(Upload);


Button.setToolTipText("Upload");


Button.addActionListener(new ActionListener()
{


public void actionPerformed(ActionEvent e)
{


int returnVal = fc.showOpenDialog(ActionDemo4.this);


if (returnVal == JFileChooser.APPROVE_OPTION) {


File file = fc.getSelectedFile();


String aa=file.getAbsolutePath();


textArea3.append(aa);


textArea2.append("Local URL:");


long l=file.length();


try


{

byte buff[]=new byte[(int)file.length()];


InputStream fileIn=new FileInputStream(aa);


int i=fileIn.read(buff);


String conffile=new String(buff);


String str1=textArea10.getText();


url = new URL ("http://127.0.0.1:7001/servletUpload?x="+str1);


urlConn = url.openConnection();


urlConn.setDoInput (true);


urlConn.setDoOutput (true);


urlConn.setUseCaches (false);


urlConn.setRequestProperty("Content-Type","multipart/form-data;boundry=----
-------------------------7d11e410e500f2");


printout = new DataOutputStream (urlConn.getOutputStream ());


String content ="-----------------------------7d11e410e500f2
"+"Content-
Disposition: form-data;"+"name="upload";
filename=""+aa+""
"+"Content-Type: application/octet-
strem


"+conffile+"-----------------------------7d11e410e500f2--

";


printout.writeBytes(content);


printout.flush ();


printout.close ();



Best Regards


Bikash

   <<Less
About | Sitemap | Contact