• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

big file upload to server with resume function

Hi

I am trying to write a file upload program to a server through sockets.
as thefile may be very big, i need a resume function in case connection breaks and i can pick up the upload from where it was broken.

Is there any example or source codes out there?

Hope it is not too complicated
0
linchong
Asked:
linchong
  • 7
  • 6
  • 2
  • +1
1 Solution
 
sudhakar_koundinyaCommented:
0
 
aozarovCommented:
If you are not using some library that provides the communication protocol (such as ftp) then you
can have as part of your communication protocol some negotiation about the start from byte value.
Then you can use in the client side RandomAccessFile http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html
to perform seek to that position and then use its read method to start reading from it.

randomFile.seek(position);
byte bytes[] = new byte[1024];
int length = 0;
while ((length = randomFile.read(bytes)) > 0)
   out.write(bytes, 0, lenght);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
linchongAuthor Commented:
which means if the connection breaks, i check the length of uploaded file currently in server. get this position.

when client try to resume upload,  send back the last positon to client to start from that position and resume upload??

0
 
CEHJCommented:
You need both sides cooperating to do this or the partial file on the server probably will just get clobbered by the resumed upload. Are you implementing this yourself? Why not do it with FTP? This has the APPE command that appends to a file
0
 
linchongAuthor Commented:
but FTP upload has not resume function. only download has it.

where can i fidn the example??
0
 
CEHJCommented:
>> but FTP upload has not resume function

That's not the case. The APPE command does just that effectively (it appends to a file). You need a library that supports that
0
 
linchongAuthor Commented:
where can i find an example on this??
0
 
linchongAuthor Commented:
also, there is no ftp server over the other end

it is just an url socket server ..  I am taking inputstream to bytearrays and then to fileoutput
0
 
CEHJCommented:
>> also, there is no ftp server over the other end

Then this discussion of ftp is somewhat academic unless you use one. You'll need to develop a custom protocol whereby the receiving file can be appended to
0
 
linchongAuthor Commented:
what i have in mind is to name this file with ref to userid n filename.
whatever recvd thru socket will be appended to this file.

i have never try RandomAccessFile yet. not sure what is the maximum file size available. And whether it would fit into this scenario.

any better ideas?
0
 
CEHJCommented:
There's no need to use a RAF to append to a file. Just open the output stream on it in append mode
0
 
linchongAuthor Commented:
if connection breaks, it is a new session .......
i need to know where it had stop,  pick up fro that point and resume
0
 
linchongAuthor Commented:
can someone explain to me how ftp resume works??  I need an idea how it works
0
 
CEHJCommented:
>>i need to know where it had stop,  pick up fro that point and resume

You need a strategy for communication between both ends so you know the state

>> can someone explain to me how ftp resume works??  I need an idea how it works

Resume works from the downloading standpoint - you're uploading
0
 
aozarovCommented:
>>  have never try RandomAccessFile yet. not sure what is the maximum file size available
You want to use the RandomAccessFile in the client side where you want to read data from a file starting at a specific position.
I provided you example of how to do that.

>> send back the last positon to client to start from that position and resume upload??
Yes, the negotiation can be:
   client -> going to upload file X
   server -> accepting file X start from point Z
   client -> loading the file from point Z (using the seek to byte Z)
                                           
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 6
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now