How to load Images from Java Server+MySql to Android Client - java

I've a social networking app for android in which i can view list friends after fetching from java server +mySql database, actually i have done with loading all information from Java Servlets to android client but i'm unable to load images which are stored as blob in mysql on the server side database.
I tried to send blob objects to android client as strings and then tried to convert them in bitmap at the android client side. but I could not do what i wanted.. :(
Can anyone suggest me how to do it?

I think a viable solution is to put a simple blob servlet capable to send a image/your_image_format response via HTTP. This way you can easily download/decode the Bitmap in your Android client from the servlet response, then set it as your ImageVIew source.

Related

Android studio jDBC not connecting to the mysql server with jdbc [duplicate]

This question already has answers here:
Can an Android App connect directly to an online mysql database
(8 answers)
Closed 6 years ago.
I have a website already setup which uses mysql database. I want to know how can i connect my app to that database.
What i wanna achieve is that my app should make a request to find a table of a defined "ID" or name. The table contains links to images or image names. I want the app to retrieve those images and display them on the android app.
What are the ways this can be done?
Can I use PHP to develop an android app?
Android does not support MySQL out of the box. The "normal" way to access your database would be to put a Restful server in front of it and use the HTTPS protocol to connect to the Restful front end.
Have a look at ContentProvider. It is normally used to access a local database (SQLite) but it can be used to get data from any data store.
I do recommend that you look at having a local copy of all/some of your websites data locally, that way your app will still work when the Android device hasn't got a connection. If you go down this route then a service can be used to keep the two databases in sync.
The one way is by using webservice, simply write a webservice method in PHP or any other language . And From your android app by using http client request and response , you can hit the web service method which will return whatever you want.
For PHP You can create a webservice like this. Assuming below we have a php file in the server. And the route of the file is yourdomain.com/api.php
if(isset($_GET['api_call'])){
switch($_GET['api_call']){
case 'userlogin':
//perform your userlogin task here
break;
}
}
Now you can use Volley or Retrofit to send a network request to the above PHP Script and then, actually the php script will handle the database operation.
In this case the PHP script is called a RESTful API.
You can learn all the operation at MySQL from this tutorial. Android MySQL Tutorial to Perform CRUD.
Yes you can connect your android app to your PHP to grab results from your database. Use a webservice to connect to your backend script via ASYNC task and http post requests. Check this link for more information Connecting to MySQL
Use android vollley, it is very fast and you can betterm manipulate requests.
Send post request using Volley and receive in PHP
Basically, you will create a map with key-value params for the php request(POST/GET), the php will do the desired processing and you will return the data as JSON(json_encode()). Then you can either parse the JSON as needed or use GSON from Google to let it do the parsing.

Is it secure to build android app that works with PHP API on browser?

I'm learning to build android apps using java & android studio.
For my app i need internet connection and a server side database, I'm already php developer so i tought to build a PHP web API and by json, send and recieve data from specific URL.
For example, any user that will register inside my app, i can send his data to:
(via POST or GET method.)
example.com/api/user_register.php
Is it secure? How can i get data and send to an existing domain in java?
I'm looking for something similliar to file_get_content() or CURL in PHP.
Also i need to build something like push notifications..
Creating an web API to access a MySQL Database for Android is expected as there is no direct connection to the database possible on Android.
I've done something similar with one of my own apps. How secure it is depends on how you make it and where your PHP API is. I.e. is the data being sent to/from HTTP or HTTPS. In my own app, I encrypt the post data on the device, post it to my PHP API which decrypts and processes the request.
It then builds a response and json_encodes it, which is then encrypted and sent back to the device, where the device decrypts it and processes the JSON result. All of this is also done over HTTPS so hopefully, its fairly secure.

Storing Images of a Java based REST service running on Heroku

I am currently developing my first Java based RESTful service that should be run on Heroku. This service manages some objects that have associated images. As Heroku is not able to store this images (apart from storing them in a database), I thought of using an external Content Delivery Network (CDN) like Amazon CloudFront. My first attempt to implement this would be as followed:
Encode the image (base64) on the client side.
Send the encoded image encapsulated in Json to the server side.
Decode the image on the server side.
Process the image (scale, create thumbnails, etc.).
Store the image in Amazon's CloudFront using the AWS SDK for Java.
Store a link to the image with the associated object in a postgreSQL database.
Now my question is, if this is the way to go, or if there is a better way to do this and if this GitHub project is a good point to start. If this helps to give an answer - the images are used within desktop and mobile as well as in web-applications.
Store the image in Amazon's CloudFront using the AWS SDK for Java.
Er, CloudFront doesn't store things, it caches things. If you want it stored, you need to put the image on S3 and pay for it every month.
Encode the image (base64) on the client side
Er, why? Just do a PUT or multipart-mime POST, and send the file as bytes.
Send the encoded image encapsulated in Json to the server side
Again, there's no reason to encode it, you can send the metadata + data in the same POST easily without encoding.
Store a like to the image with the associated object in a postgreSQL database
Storing images in a database is an anti-pattern. It makes the database harder to backup, slower to query, etc. Generally, you want to put the image in S3, and store the path in the database.

Redirect Restful directly to Couchbase to reduce encoding decoding

Could any one of you suggest what would be the proper solution to this design.
Here is what I'm trying to accomplish and I'm not sure whether it's all possible.
Infrastructure
Android > Php ZF > Couchbase
So all communication is done using Restful. Currently how it works in my apps is as follow. Android requesting an image file say jpg/png to my apps via Restful. Myapps needs image file stored in the Couchbase so it contacted Couchbase via Restful, received file in apps server, decode the restful from base64 back to jpg/png , Encode the data again to base64/Json, transfer it to Android device. Android device received the Json in base64, decode it back to the jpg/png.
Does this movement make sense?
So in order to cut down on decoding>encoding>decoding. I'm wondering whether it's possible for me to have my android contact the Couchbase directly via my PhpZF apps server and just do decoding once after it arrived at the android device?
Please advise? Many thanks everyone. Hope this make sense on what I'm asking for?

How to transfer images from Android client to Java server

I am trying to developer an Android application which allows to capture pictures with the camera, and send the pictures to a Java server.
I don't need the picture after, so I do not need to store it in the phone locally.
I was able to successfully to transfer simple text from client to server, but I'm having problems with images.
What do I need to do to be able to send images from the Android client, and should anything special be made in the server apart from what it is doing now?
Solution is to use http request with MultipartEntity.

Categories