I am currently working on an android application and I would like to add a file system to send images. But I don't know how to get an image from the local storage of an android, nor how to send it to a server. I am currently using a flask server to retrieve JSON files, and I don't know if retrieving images would be possible with this kind of server.
Would you have any clue how to retrieve a file on a button press and send it to a server please?
You can use this library to pick from local storage and upload it to the server with ease
https://github.com/gotev/android-upload-service
At this point, it doesn't matter what server you use as long as you can retrieve data.
You can do it using Retrofit. For detailed instruction, check This medium post!
Related
I have a problem with my application, and I was wondering if you guys could help.
So, I am making an application that communicates with a server that contains a SQL database. I am going to store a link of the user profile picture in the database. However, I want the pictures to be stored on my server - ubuntu server on raspberry pi 2. I've been looking around, but I cannot find a good tutorial on how to upload a file to the server at a specific location. So basically, I want to take a bitmap file, and then send it to my raspberry pi.
I would really appreciate it if someone could help me out. Thanks!
You can convert your file to a base 64 string and then send it
refer to this solution:
Android - Send Image file to the Server DB
I have some questions about developing a Android application which shall be able to communicate with a NodeJS server.
The Android application gathers some data and saves everything in a .csv file.
This file now needs to be uploaded to a NodeJS server. The NodeJS server should save the file as well as storing the content in a MongoDB.
My question now is how I should implement the communication between the Android device and the server.
I know how to upload a single file to a NodeJS server using a HttpURLConnection with a DataOutputStream.
But I need more than just uploading the file because I need a unique identification of each Android device.
I thought about using the (encrypted) Google account E-Mail address of the user to distinguish the devices. I am not interested in knowing who uploads which data but I need to store the data for each device separately.
The problem is that I don't know how to communicate between the device and the server.
If I upload a file via HttpURLConnection and DataOutptStream it seems that I can only upload the file without any additional information like the unique key for the device.
I also thought about uploading the file via sockets. But I am not sure how to handle huge file sizes (5 MB or more).
I am not looking for code fragments. I rather need some hints to the right direction. Hopefully my problem was stated clearly and someone can help me with this.
Using a HttpUrlConnection on the Android side, and a RESTful server on the Node side would be a straightforward option.
You can embed information into the URL in a RESTful way:
pathParam: www.address.com/api/save/{clientId}/data
queryParam: www.address.com/api/save/data?c={clientID}
each uniquely identifying the client. This can be whatever scheme you choose. You will have to build the HttpUrlConnection each time as the URI is unique, and important!
The server side can then route the URL however you see fit. Node has a number of packages to aid in that (Express, Restify, etc.). Basically you'll grab the body of the request to store into your DB, but the other parameters are available too so it's all a unique and separated transaction.
Edit: The package you use for RESTful handling can stream large files for you as well. Processing of the request can really begin once the data is fully uploaded to the server.
Using a socket would be nearly just as easy. The most difficult part will be 'making your own protocol' which in reality could be very simple.
Upload 1 file at at time by sending data to the socket like this:
54::{filename:'myfilename.txt',length:13023,hash:'ss23vd'}xxxxxxxxxxx...
54= length of the JSON txt
:: = the delimiter between the length and the JSON
{JSON} = additional data you need
xxx... = 13023 bytes of data
Then once all the data is sent you can disconnect... OR if you need to send another file, you know where the next set of data should be.
And since node.js is javascript you already have wonderful JSON support to parse the JSON for you.
Would I suggest using a socket? Probably not. Because if you ever have to upload additional files at the same time, HTTP and node.js HTTP modules might do a better job. But if you can guarantee nothing will ever change, then sure, why not... But that's a bad attitude to have towards development.
My app should have capability to work online and offline.
When I have internet, I will connect to tomcat server and fetching the json object and displaying the details.
But if I don't have internet access, I want my app to work. So my idea was to store the data in xml files in mobile at some folder when my last communication done with server. Is it possible?
If so how can I do it.. Can anybody help me ???
You can store the data in your internal memory and every time you hit the server delete the old contents.
Maybe you can use Preferences or a database
we have a text file stored on our server where I work, and I have searched on how to read in a specific line from that text file and have it display on the screen of my Android activity... but I haven't found a solution yet. Only two words, or so, of the text in the file on the server will be changed/replaced periodically, and I would like those changes to take effect/be updated in my Android app each time. Not sure why I couldn't find an answer to this yet. Any help is much appreciated! Thank you!
Actually the best way to have a secure transaction between an android app and server is to use web service like JSON. You request something from your android app to server, Then in server request will be analyse and response to your android app. You can send some request that tell the server what to do. Then in server side have a script that do your job and send response to your android app.
I have an Android app that fetches data from the web service using ksoap2, the web service in turn fetches that information from SQL Server and sends it to the app, ksoap2 is fast and reliable and I'm happy with it.
I'm about to add a new feature which is the app will fetch multiple images from the server too. I searched for the best way to do this and I landed on three options:
keep using ksoap2 and store the images on the SQL Server, the web service will send the images in binary strings and then the app with render them and display them.
Store the images on the hard drive and use HttpUrlConnection, the web service will send the images path (url) through ksoap2 and the app will use HttpUrlConnection to download the images and display them.
Use JSon
My question is, from your experience which way should I go for? or maybe you have a better solution than that?
Thanks.
I would use option #2:
Store the images on the hard drive and use HttpUrlConnection, the web service will send the images path (url) through ksoap2 and the app will use HttpUrlConnection to download the images and display them.
This gives you the benefits of ksoap2, without a hacky workaround trying to jam images into SQL binary strings.
Additionally (and this is without knowing anything about the app you are creating) it allows you to only load the images when you actually need them, saving bandwidth, battery and memory.