0

I have an android application which stores image in WAMP (i.e C:\wamp\www*projectName**Image folder*) at the time of registration. i am using WAMP as local server, Retrofit for network activities and glide for image processing. Image is uploading successfully and image path is being stored in DATABASE. Now when i retrieve the information from database, i want to display that image in imageView using glide but i don't understand how i do that. In JSON response i am getting the path of the image.

==================================================================

My Php Script for uploading photo

$image = $_POST["uPhoto"];



$time = date("d-m-Y")."-".time();
$image_name = $username."_".$time;
$image_path = "user_profile_images/$image_name.jpg";

if (mysqli_query($myCon,$sql))
    {

        file_put_contents($image_path,base64_decode($image));

        $status = "ok";
        echo json_encode(array("response"=>$status));
    }

==================================================================

JSON Response

  "Photo Path":"user_profile_images\/roots123_29-08-2018-1535553004.jpg"

In android side i am trying

 Glide.with(getApplicationContext()).load(response.body().getImage()).into(imgProfile);

Can someone please give any solution

  • What are you getting in `response.body().getImage()`? It should be the image url in the load function of Glide library. – Kunu Oct 04 '18 at 11:52
  • when i am debugging the app and checking step by step, i see that in image its showing null. – Anonymous MK Oct 04 '18 at 16:59

5 Answers5

0

To get your image from local wamp server you need to prepend url with ip of your pc in which your wamp server is running If you are testing with remote android device in same network with your server. If you want to test with emulator you can try with following ip 10.0.2.2.

karan
  • 8,637
  • 3
  • 41
  • 78
0

First of all you check your complete image path (url= your system local ip + user_profile_images/roots123_29-08-2018-1535553004.jpg) in browser, if it display the image then you can load this image in your app by using glide you can check you system ip in Task manager or command prompt by using ipconfig command. check your ip in browser ip run your local host server in browser

String Img_url = "system ip"+response.body().getImage();
Glide.with(getApplicationContext()).load(Img_url).into(imgProfile);

use it in your android emulator

Divyanshu
  • 462
  • 6
  • 17
  • my local is 192.168.0.102 and path is C:\wamp\project\user_profile_images\roots123_29-08-2018-1535553004.jpg when i combine those, i am getting 403 error forbidden access. – Anonymous MK Oct 04 '18 at 17:03
  • check this ulr like this `http://192.168.0.102/user_profile_images\roots123_29-08-2018-1535553004.jpg`, i hope it work – Divyanshu Oct 05 '18 at 04:46
0

after you double checked the url and making sure always clear catch and then reload the image into the image view :

Remove image from cache in Glide library

Namini40
  • 100
  • 7
0

When you using Glide it may happen Glide library taking catch so you need to first clear catch from memory and then try to load image from URL try this code where you load image

  • Glide.with(YourActivity.this) .load(Uri.parse("file://" + imagePath)) .diskCacheStrategy(DiskCacheStrategy.NONE) .skipMemoryCache(true) .into(mImage);
0

if you are using retrofit for the network call ,make sure you have created the interface for the network call and your image list is ready like this:

Your Interface:

interface ImagesApi {
@GET("/api/images/")                   
fun getImages(): Call<ImageDataClass>
}

Your Data Class:

data class ImageDataClass(val id: Number?, val imageUrl: String?,val description: String?, 
 val created_at: String?, val updated_at: String?)

After then make a call and get the image List.Now in the View use glide as:

 Glide.with(this)
                .load(imageList[index].imageUrl)
                .override(width,height)
                .into("your image view")

Hope this will help