Glide不会加载某些图片网址

时间:2016-05-11 01:46:42

标签: php android android-glide

我创建了Restful Api,因此用户可以与我的服务器数据库进行通信。首先,我将用户从Gallery中选择的图像上传到数据库中,使用函数将位图转换为字符串:

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);
}

之后我将图像路径存储在数据库中并使用PHP中的这些代码解码编码图像:

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

图像的结果如下:

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

当我尝试从适配器获取此URL时,我什么都没得到。这是我用过的代码:

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);
        }

我知道网址有问题,因为当我尝试加载一些像这样的随机网址时:

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

它正在运作。那么我的网址可能有什么问题?

1 个答案:

答案 0 :(得分:0)

如果有人像我一样遇到同样的问题,那就别忘了把

http://表示您在数据库中存储的图像路径。对我来说就是这样:

我这样做是错误的:

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

这应该是它的样子:

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