how to download PDF file from server. - android

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.

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.

Related

How to send big size image to a server in android?

I have to send a DNG file which has a size around 30 mb to my server and then I have to process DNG file in matlab and after that I need to get the results back from matlab to android device. I am new to sending images to a server and I do not know if is there any special way for big size images. I saw similar questions but I could not understand what to do for sending images to a server.
Could you please help me which steps should I follow respectively and which methods or libraries do I need to use ? Thanks.
If you'd like to send big files using HTTP, chunks are the way to go.
You would need a backend server supporting this kind of operation (either with some homemade recipe or with a standardized implementation).
You'd basically need an API to create the file description (including the expected size) which would return a handle on this future file (at least an ID). Then use PUT or PATCH and send the chunks one by one.

File upload from android to server with socket.io nodejs

I have integrated socket.io into my android application to make a chat application. Now I wants to upload and share files like images, mp3 or doc file etc. How do I upload a file with socket.io I cannot find any documentation for doing.
It is not a good practice. This may lead blocking heartbeat messages between client and server if upload progress is long.
You may upload file with http post and send download link to chat peer. By doing this, a new connection is established for uploading and never breaks socket.io session.
I believe it should be a good practice to do in Android, as it works pretty well on web JS for small files such as Images, PDFs, etc.
But ya sending the whole file in a single shot is not a good practice(theoretically there should be no problem in doing that using socket.io), but it's better if you can the fragment the file into smaller pieces (maybe 2^10 to 2^20 bytes), and send it in pieces, doing so will also allow you to know the percentage of file's data transferred.
I am not good with JAVA, but I hope you can find a way to do that fragmentation thing.
But there is no inbuilt resource available in socket.io to transfer files, but you won't have any problem in sending pure Buffer(including '\0' in it) if you can manage to create a JSON object in JAVA without involving strings. As '\0' inside Strings messes them up.

Using an online .txt file as a data source

I am building an Android app for a client and most of the data that i need is contained in an online .txt file attached to my clients website. I've never used an online .txt file as a data source before and don't really know where to begin?! Can anyone point me in the direction of a good tutorial on the subject.
Many Thanks in advance
P.S. I haven't asked whether it's possible because i have assumed it is due to the fact you can use an internal .txt file as a data source
I think the best approach is to download the file on the device and then read it like a normal file. If the file changes on a period of time, then configure the app to download and read the file and then update the local info in the app.
I don't think you can use an online txt as a DataSource, but you can implement this so you have an abstract source for your file, and then just call read on it.
Expose the txt/xml file over web,if you want to get it down to phone use URL loader and load it to the phone and operate if you want to use it online (like others may also be using it) it will be a bit complex in order to deal with data coming from more then one source but possible. clear you question a bit more.

Upload file for primitive chat

I need a fast way to upload files to a ftp server.The files will be used for a primitive chat.Something like a timer and every 5 sec checks to see if the file x was added,if it was added open it and show it.
So please tell me an easy way to upload a file,because from google,I got only hundreds of lines of code.And yes,I need it for a FTP server.
Also it would be awesome to tell me a way to acces a file trough ftp open it and show it.(don't really need to download).
You should use the org.apache.commons.net.ftp.FTPClient library - it's free and implements fairly easily with Android. You can find a pretty easy how-to at the bottom of this blog post:
http://hoang17.com/posts/android/android-how-to-upload-a-file-via-ftp
That article should be especially helpful as it shows you how to store a string as data in a specific filename.
To be honest though - FTP seems like the absolute worst way to create any form of chat communication. :)
Cheers.

How to download only the first part of a .csv file on Android?

In my app, I have to present a few numbers from a .csv file that's accessible from the web. Now, this .csv is quite big. I don't want to download and process the whole thing, there's no point. My numbers are always in the beginning of the file, in well specified positions - lets say position 5 to 10.
Could you give me some tips on how to implement this? I know how to download the whole thing, but don't know how to download only a part of it.
Thanks.
Psuedo:
BufferedReader br = new BufferedReader (new InputStreamReader(remoteStream));
String sFirstLine = br.readLine();
remoteStream is the stream of the connection to the remote server. Getting a handle to the stream is not the same as actually downloading. Only the BufferedReader.readLine() actually downloads anything
Do you have access to the server the file is on? You could do your processing on the server.
For example, if the file is at /myfile.csv, you could open a stream to mycsvfile.php on the server, which does the processing and returns the positions you're interested in. Of course you'd also have to write the PHP code (or whatever) to do this.
You don't say what protocol the file is served under, but assuming something standard like an http or ftp there should be nothing to stop you from starting the download and then aborting it once you've gotten as much of the file as you need, provided that you implement the android end of the protocol yourself rather than using one of the built in mechanisms (unless you find the built in mechanism also gives you the ability to abort).
I don't believe the implementation of a simple http downloader in java or ndk to be too complicated. Doing it on android should not be uniquely challenging as you have all of the normal java and underlying linux network sockets mechanisms readily available.

Categories

Resources