0

I am trying to download a file from server, what I have in mind to get filename in json response and the content and write same in assets or on sdcard. should i go and implement same, or there can be some other way we can achieve the same.

AAnkit
  • 27,299
  • 12
  • 60
  • 71

1 Answers1

1

Actually you know you control the way you expose the content from the server - you can just make the file itself (its bytes) exposed at certain url. If you need to keep the name of the file posting as json seems to be good solution.

However, there is one trick here: I don't know how big the file you refer to is and also how reliable the network will be. For every bigger file I will recommend to implement resumable upload via byte serving. You can read about the byte serving client consumer in Android in this thread. Then just go and see on how to implement byte serving server side - it definitely depends on the platform in the only case in which I used such mechanism I actually had to mimic the byte-serving with my custom url parameter. If you need further help on server side write back and I will extend my answer.

Community
  • 1
  • 1
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
  • Thanks Boris, server is of the client for whom i am developing app, and the pdf is not going to be big in size... !!! any good way you know about synching with server in some interval?? – AAnkit Jan 18 '12 at 17:18
  • What do you mean "in some interval" do you refer to time interval i.e. syncing every 4 hours or to byte interval, i.e. syncing some portion of the file. – Boris Strandjev Jan 19 '12 at 07:52
  • time interval, Sorry for incomplete info – AAnkit Jan 19 '12 at 08:02
  • The syncing in android is implemented via sync service. See this example it shows how to implement it: http://developer.android.com/resources/samples/SampleSyncAdapter/index.html. However I have never been able to implement it in specified time interval (maybe haven't read enough). The default sync interval is once a day if I am not wrong, which might be unsufficient for you. There are two alternatives: thread that sleeps for specified amount of time and using server push (which is not an option if the client supplies the server). – Boris Strandjev Jan 19 '12 at 08:10
  • Thanks Boris, for my last app i did use Alarm Manager class which triggers after some time interval and call a thread which do synching, it was working perfect but I my self not happy with this, as I want to use more generic way, I will go through the link, And get back to you, thanks for your time. keep in touch.:) – AAnkit Jan 19 '12 at 08:18