• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Image file and size of the file

 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
And when I select file above 4mb size then it gives me error on Dos-prompt(java.awt.Component.processMouseEvent(Component.java:3165)
at
java.awt.Component.processEvent(Component.java,
Compiled Code)
at
java.awt.Container.processEvent(Container.java,
Compiled Code)
at
java.awt.Component.dispatchEventImpl(Component.java,
Compiled Code)
at
java.awt.Container.dispatchEventImpl(Container.java,
Compiled Code)
at
java.awt.Component.dispatchEvent(Component.java,
Compiled Code)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java,
Com
piled Code)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java,
Comp
iled Code)
at
java.awt.LightweightDispatcher.dispatchEvent(Container.java,
Compiled
Code)
at
java.awt.Component.dispatchEventImpl(Component.java,
Compiled Code)
at
java.awt.Container.dispatchEventImpl(Container.java,
Compiled Code)
at
java.awt.Component.dispatchEvent(Component.java,
Compiled Code)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java,
Com
piled Code)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java,
Comp
iled Code)
at
java.awt.LightweightDispatcher.dispatchEvent(Container.java,
Compiled
Code)
at
java.awt.Container.dispatchEventImpl(Container.java,
Compiled Code)
at
java.awt.Window.dispatchEventImpl(Window.java,
Compiled Code)
at
java.awt.Component.dispatchEvent(Component.java,
Compiled Code)
at
java.awt.EventQueue.dispatchEvent(EventQueue.java,
Compiled Code)
at
java.awt.EventDispatchThread.pumpOneEventForComponent(EventDispatchTh
read.java, Compiled Code)
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\r\n"+"Content-
Disposition: form-data;"+"name=\"upload\";
filename=\""+aa+"\"\r\n"+"Content-Type: application/octet-
strem\r\n\r\n\r\n"+conffile+"-----------------------------7d11e410e500f2--
\r\n";
printout.writeBytes(content);
printout.flush ();
printout.close ();
Best Regards
Bikash
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!