6

I want to be able to transfer blocks of my file instead of the complete file from my app inorder to transfer it more efficiently. What is the best way to do that?

Update

Here is an example of where I would need this approach : Say I have a 4GB file which I am trying to upload. If the network fails, my file upload will stop and I will have to start from scratch. Instead, if I keep track of the blocks that I have already transferred, I can continue from the blocks which were yet to be transferred. This is especially important for flaky network connections.

Vinay Gaba
  • 1,156
  • 3
  • 12
  • 26
  • Just out of curiosity - what is your underlying assumption that you can beat the OS's I/O efficiency? What medium are you transferring through? – runDOSrun Mar 15 '15 at 13:43
  • I think he means to transfer only certain "blocks" of his file at a certain time, _not_ the entire file at once "in blocks". Still, that's a fairly broad question and can't really be answered without a lot more detail on the actual use case. For a start, you could show us what you're doing right now. – ci_ Mar 15 '15 at 13:48
  • My intention of this approach is say I have a 4GB file which I am trying to upload. If the network fails, my file upload will stop and I will have to start from scratch. Instead, if I keep track of the blocks that I have already transferred, I can continue from the blocks which were yet to be transferred. This is especially important for flaky network connections. – Vinay Gaba Mar 15 '15 at 14:55
  • Please check http://www.cuelogic.com/blog/android-code-to-upload-download-large-files-to-server-2/ to upload chunks on server. it may help you. – Hiren Dabhi Mar 24 '15 at 06:14
  • I think his understanding is that the OS transfers file very much randomly and he wants to programmatically control what to transfer and how much to transfer – user4582135 Mar 15 '15 at 13:55
  • Sorry had to comment but submitted as an answer – user4582135 Mar 15 '15 at 13:56
  • Updated the description to describe the scenario where I would need this. – Vinay Gaba Mar 15 '15 at 14:58
  • Also what you said could also be a valid case. – Vinay Gaba Mar 15 '15 at 14:59

2 Answers2

1

May i know what kind of file you have. ?I am asking because if it is other than text file then i think you need meu law and A law or G711 or G729 algorithm.

DJhon
  • 1,548
  • 3
  • 22
  • 39
1

I figured out one approach to do this. What you could do is divide the file into blocks using the approach mentioned here - How to break a file into pieces using Java? and convert each block into a Base64 string and then transfer the encoded string. The server responds with the chunk number after it receives it. This chunk number can then be saved on the device locally and the next chunk can then be sent to the server. After all the chunks have been transferred, the Base64 decoding can be done on the server side and the files can be merged.

Community
  • 1
  • 1
Vinay Gaba
  • 1,156
  • 3
  • 12
  • 26