How to send large files in chunks ?

105 views
Skip to first unread message

Gerry

unread,
Jun 2, 2014, 4:43:20 AM6/2/14
to sardi...@googlegroups.com
Hi all,
could anybody point me in the direction how to send large (binary) files in chunks to my unreliable server ?

The SARDINE API  put () allows lots of options.  But I'm missing something like sending byte[ ]  with an 'append' option.

Thanks for any hint.






Jon Stevens

unread,
Jun 2, 2014, 11:54:59 AM6/2/14
to sardi...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "sardine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sardine-dav...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gerry

unread,
Jun 3, 2014, 8:06:50 AM6/3/14
to sardi...@googlegroups.com
Sorry,
a not very helpfull answer. Of course I read the API specification.

All SARDINE put() operations are atomic. Crashed uploads are not
resumed and you have to restart from start.

I tried
    sardine.put(uri, new FileInputStream(file), "application/octet-stream", true, file.length());
If the connection breaks, it is not resumed.

Moreover it sets HTTP header 'content-lenght', but that's not what I need.

Solved it in the meantime:
HTTP header 'CONTENT_RANGE' is what is needed (found it in the Junit tests of SARDINE.)

To whom it may help: this is how I did it:
 
 while bytes in stream {
    ...
 // total size is mandatory. Should not be file.lenght() cause it allocates the full file size immediately and you do not know where to resume.
   header.put(HttpHeaders.CONTENT_RANGE, "bytes " + from + "-" + to + "/" + to );   

    sardine.put(uriString, new ByteArrayInputStream(byteArray) , header);
    ...
}

I used FileChannel and  MappedByteBuffer to read the file in chunks.

Suggestions and improvements are welcome.
 

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages