linchong
asked on
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
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
http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html
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);
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);
ASKER
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??
when client try to resume upload, send back the last positon to client to start from that position and resume upload??
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
ASKER
but FTP upload has not resume function. only download has it.
where can i fidn the example??
where can i fidn the example??
>> 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
That's not the case. The APPE command does just that effectively (it appends to a file). You need a library that supports that
ASKER
where can i find an example on this??
ASKER
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
it is just an url socket server .. I am taking inputstream to bytearrays and then to fileoutput
>> 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
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
ASKER
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?
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?
There's no need to use a RAF to append to a file. Just open the output stream on it in append mode
ASKER
if connection breaks, it is a new session .......
i need to know where it had stop, pick up fro that point and resume
i need to know where it had stop, pick up fro that point and resume
ASKER
can someone explain to me how ftp resume works?? I need an idea how it works
>>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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.