Вопрос

I have one android application where admin user can create normal user account in which admin user can select photo of normal user to create account. Things are working great till i am storing normal user name,Age ETC. But problem arises when i want to store image of normal user to database. I am using Wamp server as back end database.

Can you guys please suggest me how to store image in WAMP server as well as how to retrieve it again so that i can display on android activity.

Functionality is like, Admin User login ----> Create Normal User --> Select Image --> Store in database.

Normal user login --->Retrieve image from Database --> View image in Android activity.

Это было полезно?

Решение

I think you are trying to store images in a database and a normal user can see them. I think your problem is how to store images in the database, right? If I'm correct you can store image names instead of imagse like you would store age and name.

For example you can create a folder called images then you store all the images in this folder. When you want retrieve an image you can get the url/a link pointing to the image.

For example when an admin stores an image named "image1.jpg" you can program to store the picture to the image folder and also set the name in your database, then this image has a specific id and a url and when a normal user wants to retrieve the image you should instruct your code to get the id and then the respective url which are stored in your database as a string.

For a reliable handling you can create folders like image_jpg image_png, image_gif and so on. Then progmatically check the image type when the admin uploads photos and store them in the correct folder according to the type. And also you can store id, type and name in your database then check the type and create the full path url according to these parameters when you present them to the user

.....................

id   | type |name

0001 | jpg  |image1

0002 | gif  |image2

.....................

When a normal user wants to see an image all you need is the image name and the path/url. In this example the image url for

0001 is   "path/image_jpg/image1."+type
0002 is   "path/image_gif/image2."+type

When you know the id you can get the type then it's easy to create the path or url for your image...

Другие советы

Another way of storing image in server is using webservice. do as follow:

Server Side

A. Accept image from client device

 1. create webservice to accept image as base64 string.
 2. convert base64 to image and store on server directory.
 3. save the path of image in DB.

B. Send image to client devices.

 1. create webservice to send image to client device
 2. retrieve image path from DB.
 3. generate Image URL and sent it as response to client device

Client Device android

A. send Image to server

 1. convert image to base64 String.
 2. call webservice to send image as base64 String.

B. Retrive Image

 1. call webservice to retrieve image URL.(Best way to get image is using lazzy loading)

I guess you are using simple form http post to create details in wamp server. But if you want to upload images/file then you will have to use multipart request.

If you are saving the image as binary in db, then during retrieval 1. Send it down as a stream, esentially the client will have to download the image and show it as required. 2. Generate the image and save it on your server and send back a url which the client can use to retrieve image.

create database create table with image attribute (write data type of image is blob) insert into table_name values(load_file('location of image where image is stored')) then do and open image

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top