Downloading and storing images - java

I am currently working with Fragments, one of my fragments is "User Profile" where the signed in user can edit and view their own profile. One of the requirements for this university project is that the user needs to be able to upload a profile picture and it should be allocated to their user profile and saved on the server (I am currently using Lampp on linux). I have the following questions:
When a user uploads an image using the Volley library (Android) does it first need to save the relative/absolute path of the image to the MySQL database, and then use this information to get the image in JSON format back onto the device, where it shall be cached?
I read online that the Volley library can cache images and videos on the device, which would help data consumption so the user doesn't need to download the image(s) every time they login again. But what if the user logs into the application from say an IOS device and uploads an image there and then they come back to the Android device and logs in there - the app needs to update their user profile.
My thinking was every time a new Image is uploaded to the server the time it was uploaded would be added to a Date/Time slot in the DB, then this time is stored is the SQlite DB and the MySQL DB, every time they open the application it makes a request to the MySQL DB requesting this time field and if no images have been added then the SQLite time and the one just pulled from the MySQL database will be the same so no need to download any images - I thought this would be a simple way of checking without using a lot of data? or is there a better option someone could suggest.
However, the problem with my above suggestion is say for example there are 5 images cached on the device, but a 6th one was added from another device, when we go back to the original device how do we only download the new image? and not all of the other 5 also which are already in the cache?

I think you need to store in db not path to image file, but URI that you pass into Volley. And then, when you want to show image pass saved URI in Volley and it will decide show cached image or upload from internet.
Good thoughts. I think in your case you can just show data cached in dp, and then additionally fetch data from server, and it was changed cache it and show new results. Also you can implements long polling, or sockets, or GCM to set up connection with server and fetch new updated data immediatelly (in real cases not immediatelly but faster then "go to app -> check from request if there was changes in server side").
And of course, please have a look to firebase tutorials to think about implementing on your server side this thing and provide more interesting and covenient connection with immediate update of your local cached data. additional link to video tutroial

Related

What's the efficient way to retrieve images from Firebase in Android?

I need to store images in Firebase - storage and download them to every connected devices as soon as the image is added to the storage. However, what is the efficient way to achieve this?
Should a Firebase-job-dispatcher be used for this purpose?
Or is there any listener/methods that fetches the images and sync the storage?
The Download Files on Android docs from Firebase does explain various methods to retrieve the files such as : by bytes, via URL, FirebaseUI. However from the app perspective, how do I listen for any change in the storage(insertion/deletion of an image) and thereby performing operations in Firebase? If a new image is inserted, download it, or if its deleted, remove from app memory.
Any info regarding this would be much appreciated.
I'd suggest using Firebase database and having image url properties pointing to your images. This info will get synced back to client and you can then use something like Picasso to render the image (using the url).

Android Google Drive SDK: Saving to App Folder

For my current project, I would like to allow a user to create a sqlite database file and have them enter some content. Then the user has the option to sign into their google drive account and upload this file. Afterwards, after the user makes further edits, the new database file is uploaded to replace the old file. Finally, if the user has multiple devices, the database should be downloaded from the google drive and replace the existing file stored on the device.
Currently, I have successfully setup Google Drive SDK authentication and I can sign in to the app with my account.
My main question is, how do I upload a sqlite database file to the APP FOLDER when I choose to press a sync button? (This method should be called when the user needs to sync)
Additionally, how do I upload a sqlite database file to the APP FOLDER?
Your question is a bit broad, but I'll try to send you in the right direction.
First you have to decide if to use the REST Api or GDAA. Both will accomplish the same (actually the GDAA's functionality is a bit narrower now, but for your situation will do).
The big difference is that GDAA will handle on-line / off-line states for you, where with the REST Api, you have to implement some kind of non-UI thread (sync service) synchronization. Also, there are latency issues you must be aware when using GDAA.
Next, the process of uploading SQLite database is the same as any other binary data stream.
Grab the 'xxx.db' file, make output stream (or byte[] buffer) and create a GooDrive file with title + mimetype metadata, push the stream into it's content and send it on it's merry way. The only difference between a standard folder and an app folder is the parent of the file.
You get an ID you can subsequently use to download the file to the device. Or you can use search by metadata (title in your case) to get this ID. Again it comes as input stream and you dump it to an 'xxx.db' file on your device.
The second portion of your question deals with multiple devices. None of the apis will notify you about a change in GooDrive, so you must implement one of the 2 strategies:
1/ Polling (ouch), preferably in sync service with sync intervals the system gives you.
2/ GCM message broadcasted to the devices / users who are interested (not trivial, but efficient ... and sexy).
Another pitfall you must be aware when using multiple devices with GDAA is described in SO 29030110 and SO 22874657.
In case you decide to play with the 2 apis, I maintain basic CRUD implementation demos for both the REST and GDAA. The GDAADemo has also an option to work with the app folder.
Good Luck

Android application performance with soap

i am building a application for a takeaway resturant using SOAP as a webservice.
Problem:
When i try to open the application it loads every time. and if i have slow internet it will take some time which is not good for a professional application.
How can i cache the images in my mobile so it loads automatically
Possible Solution in my mind:
i think i should use the local database and sink it with internet
Use local cache system (but what if the application close).
Use arraylist to store information.
Can you guide me in that as i am stuck i do some reading but i don't feel any reliable solution on it.
You can use some libs but you can lose images if the app is closed.
Actually you can cache images with libs and save them to sdcard at the same time. You need to save Their id in database. Then take data from sdcard by id from database in case you haven't internet.

Application Architecture Suggestion

I am preparing a J2ME application,
Which is basically data capturing utility, Which reads data from end user from form and the data will be submitted to server as the application will get connection.
I am planning to capture photo also.
Now my arch. is MIDlet will fetch data from user and will store it in RMS and as the connection is available the data will be submitted to server and it will be removed locally.
The main question is is it reliable to use RMS to store data.
My one data entry will be something like + a photo[optional]
"asdjbdabhsdfjkbahsdkfbakjsdfhasfjasdfhjasdlcjalmsdhfjasdfajksdlmcfjkanmsdfgsahjkcnfhs"
suggest me arch. changes.
I'm really struggling to understand your question.
if your asking if RMS is a reliable storage method for pictures the answer is yes.
You just have to convert your image to a byte array and save. Then when you need to make it back into an image, the Image class has a constructor for making a new Image from byte array anyway. The RMS is persistent so your data will be there if you stop the app and as a default your applications RMS should only be accessible to your application (although I think you can change this manually).
I'm currently developing a peace of software witch stores pictures, audio recordings and ID strings as well as date and time stamps on the phone it's self prior to a server upload point and I use the RMS.
I'm not actually sure if there's any other form of local storage that J2ME has access to.

Image Upload directly from client to remote server? Spring/Tomcat

Just wondering what the common solution is for this. We have two web servers that are load balanced and a separate server that holds our images. Our current process is that a user uploads an image directly to the web server (which ever they are connected to) and we enter a job into our DB. Another process checks for image jobs every few mins and copies the image from the web server up to the image server.
The delay from when a user uploads to when its visible is not ideal. We could tighten the loop on how often we check for image jobs but ideally I would like to have user uploaded images to go directly to the image server rather than copying twice. How should this be done? Is there anything in spring to deal with this ? Seems like how most would deal with a CDN i would think?
I want to limit the time it takes for an image that a user uploads is available on our site...
Just give the webapp direct access to the imageserver so that it can instantly save the image on the image server. I don't see how that forms a problem.
You could insert the image on upload into your db. When the image is requested and it is not in the filesystem, you then can deliver it from db and at the same time sync it to the filesystem. If you don't want to hold all images in the db, you then could also delete it from there in the same step.

Categories

Resources