简体   繁体   中英

Glide won't load some image URLs

I have created Restful Api, so the user can communicate with my server database. First what i'm uploading image that user choose from Gallery into the database, using function for converting bitmap to string:

public String getStringImage(Bitmap bmp){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 50, baos);
    byte[] imageBytes = baos.toByteArray();
    return Base64.encodeToString(imageBytes, Base64.DEFAULT);
}

After that i'm storing the image path in database and decoding encoded image using these code in PHP:

if (!is_null($image)) {
    file_put_contents($pathToImage, base64_decode($image));
}

And the result of the image is this:

http://ashfoundation.net/uploads/82.png

When i try to get this url from adapter, i'm getting nothing. This is the code i have used:

String imagePath = joke.getImagePath();

        Uri uri = Uri.parse(imagePath);

if (Uri.EMPTY.equals(uri)) {
            viewHolder.feedImage.setVisibility(View.GONE);
        } else {
            Glide.with(mContext)
                    .load(uri)
                    .fitCenter()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(viewHolder.feedImage);
        }

I know that something is wrong with the url because when i have tried loading some random url like this one:

https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png

It was working. So what could be wrong with my URL?

If someone is having the same problem like i do, just don't forget to put

http:// for the path of image which you are storing in database. That was the case for me:

I was doing like this and it is wrong:

if($image === 'null') {
    $actualpath = "null";
} else {
    $actualpath = "ashfoundation.net/$path";
}

This is how it supposed to look:

if($image === 'null') {
    $actualpath = "null";
} else {
    $actualpath = "http://ashfoundation.net/$path";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM