Results 1 to 3 of 3
  1. #1
    NerdyGal is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default Uploading files(upto 30MB..mayb more ) to server

    Client Side :

    public static void sendBigFileToServer(String fileName, String serverFilePath, String srcPath ) throws IOException
    {
    Socket socket = null;
    try {
    Properties prop = rut.readPropertiesFile();
    socket = new Socket(prop.getProperty("SERVER.IP"),Integer.parse Int(prop.getProperty("SERVER.PORT")));
    FileInputStream fis=new FileInputStream(srcPath);//source from where the file is present which includes the filename also
    System.out.println("Sending file in socket " +serverFilePath+"//"+fto.getFileName()+"from source path : "+srcPath);
    BufferedOutputStream out =
    new BufferedOutputStream(socket.getOutputStream());
    BufferedInputStream in = new BufferedInputStream(fis);
    IOUtils.copy(in, out);// from common-io.jar
    in.close();
    out.flush();
    fis.close();

    } catch(Exception e) {
    e.printStackTrace();
    logger.error("Error in sendFilebigToServer- >> "+e);
    }
    finally{
    socket.close();
    }
    }


    Server Side:

    private void bigFileLoad(FileTransferObject fto
    ) throws Exception {

    System.out.println("Uploading Big file");
    byte[] buffer = new byte[1024*6];
    BufferedOutputStream out = null;
    try {
    System.out.println("Uploading File: "+fto.getFileName());
    BufferedInputStream in =
    new BufferedInputStream(client.getInputStream());

    out =
    new BufferedOutputStream(new FileOutputStream(fto.getFilePath() + "\\"
    + fto.getFileName()));

    int len = 0;
    while ((len = in.read(buffer,0,buffer.length)) >= 0) {
    out.write(buffer, 0, len);
    }
    out.flush();
    in.close();
    System.out.println("Storing received contents to : "
    + fto.getFilePath());

    } catch (Exception e) {
    e.printStackTrace();
    }
    finally{
    out.close();
    }

    }

    fto : Use any bean/class with getters & setters to read filenames,file upload path,source path of file or whatever info needed

    Wondering how to send 1-10GB file through socket :)

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default Re: Uploading files(upto 30MB..mayb more ) to server

    Moved from a staff-only section.

    Please go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Uploading files(upto 30MB..mayb more ) to server

    So, does that code work?
    If not (and after you've added [code] tags [/code]) then what is wrong?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 03-05-2011, 05:47 PM
  2. error in uploading files on remote host
    By imanesmaeili in forum Java Servlet
    Replies: 0
    Last Post: 02-06-2011, 12:45 PM
  3. Uploading files to server via HTTP
    By dan0 in forum New To Java
    Replies: 2
    Last Post: 03-13-2009, 06:27 PM
  4. uploading files
    By javaplus in forum Java Applets
    Replies: 1
    Last Post: 01-13-2008, 10:14 PM
  5. Uploading files to FTP
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-19-2007, 10:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •