无法使用 Fresco 从 Google 云存储加载 public 图像
Can't load public image from Google Cloud Storage with Fresco
我正在尝试使用具有 public 权限的图像设置 ImageView。图像从浏览器正确加载,但在我的应用程序中它不工作:
Uri uri=Uri.parse("https://storage.googleapis.com/mybucket/filename.jpg");
ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@Nullable ImageInfo imageInfo,
@Nullable Animatable anim) {
if (imageInfo == null) {
return;
}
QualityInfo qualityInfo = imageInfo.getQualityInfo();
FLog.d("Final image received! " +
"Size %d x %d",
"Quality level %d, good enough: %s, full quality: %s",
imageInfo.getWidth(),
imageInfo.getHeight(),
qualityInfo.getQuality(),
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality());
}
@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
FLog.d(TAG,"Intermediate image received");
}
@Override
public void onFailure(String id, Throwable throwable) {
FLog.e(getClass(), throwable, "Error loading %s", id);
}
};
PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder()
.setControllerListener(controllerListener)
.setUri(uri);
// other setters
imageView.setController(controller.build());
异常不是很清楚,我只是得到:
java.lang.RuntimeException: Unsupported uri scheme! Uri is: https://storage.googleapis.co...
at com.facebook.imagepipeline.core.ProducerSequenceFactory.getBasicDecodedImageSequence(ProducerSequenceFactory.java:176)
at com.facebook.imagepipeline.core.ProducerSequenceFactory.getDecodedImageProducerSequence(ProducerSequenceFactory.java:129)
at com.facebook.imagepipeline.core.ImagePipeline.fetchDecodedImage(ImagePipeline.java:147)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder.getDataSourceForRequest(PipelineDraweeControllerBuilder.java:82)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder.getDataSourceForRequest(PipelineDraweeControllerBuilder.java:31)
at com.facebook.drawee.controller.AbstractDraweeControllerBuilder.get(AbstractDraweeControllerBuilder.java:320)
at com.facebook.drawee.controller.AbstractDraweeControllerBuilder.get(AbstractDraweeControllerBuilder.java:317)
at com.facebook.drawee.backends.pipeline.PipelineDraweeController.getDataSource(PipelineDraweeController.java:96)
at com.facebook.drawee.controller.AbstractDraweeController.submitRequest(AbstractDraweeController.java:392)
at com.facebook.drawee.controller.AbstractDraweeController.onAttach(AbstractDraweeController.java:332)
at com.facebook.drawee.view.DraweeHolder.attachController(DraweeHolder.java:276)
at com.facebook.drawee.view.DraweeHolder.setController(DraweeHolder.java:222)
at com.facebook.drawee.view.DraweeView.setController(DraweeView.java:87)
我需要向 URL 添加其他内容吗?我的印象是可以按原样访问 public 个文件。
我通过将 URL 更改为 "storage-download.googleapis.com...." 解决了这个问题;而不是 "storage.googleapis.com";我真的花了一段时间才发现这一点,因为 Google
没有在任何地方记录它
我正在尝试使用具有 public 权限的图像设置 ImageView。图像从浏览器正确加载,但在我的应用程序中它不工作:
Uri uri=Uri.parse("https://storage.googleapis.com/mybucket/filename.jpg");
ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@Nullable ImageInfo imageInfo,
@Nullable Animatable anim) {
if (imageInfo == null) {
return;
}
QualityInfo qualityInfo = imageInfo.getQualityInfo();
FLog.d("Final image received! " +
"Size %d x %d",
"Quality level %d, good enough: %s, full quality: %s",
imageInfo.getWidth(),
imageInfo.getHeight(),
qualityInfo.getQuality(),
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality());
}
@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
FLog.d(TAG,"Intermediate image received");
}
@Override
public void onFailure(String id, Throwable throwable) {
FLog.e(getClass(), throwable, "Error loading %s", id);
}
};
PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder()
.setControllerListener(controllerListener)
.setUri(uri);
// other setters
imageView.setController(controller.build());
异常不是很清楚,我只是得到:
java.lang.RuntimeException: Unsupported uri scheme! Uri is: https://storage.googleapis.co...
at com.facebook.imagepipeline.core.ProducerSequenceFactory.getBasicDecodedImageSequence(ProducerSequenceFactory.java:176)
at com.facebook.imagepipeline.core.ProducerSequenceFactory.getDecodedImageProducerSequence(ProducerSequenceFactory.java:129)
at com.facebook.imagepipeline.core.ImagePipeline.fetchDecodedImage(ImagePipeline.java:147)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder.getDataSourceForRequest(PipelineDraweeControllerBuilder.java:82)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder.getDataSourceForRequest(PipelineDraweeControllerBuilder.java:31)
at com.facebook.drawee.controller.AbstractDraweeControllerBuilder.get(AbstractDraweeControllerBuilder.java:320)
at com.facebook.drawee.controller.AbstractDraweeControllerBuilder.get(AbstractDraweeControllerBuilder.java:317)
at com.facebook.drawee.backends.pipeline.PipelineDraweeController.getDataSource(PipelineDraweeController.java:96)
at com.facebook.drawee.controller.AbstractDraweeController.submitRequest(AbstractDraweeController.java:392)
at com.facebook.drawee.controller.AbstractDraweeController.onAttach(AbstractDraweeController.java:332)
at com.facebook.drawee.view.DraweeHolder.attachController(DraweeHolder.java:276)
at com.facebook.drawee.view.DraweeHolder.setController(DraweeHolder.java:222)
at com.facebook.drawee.view.DraweeView.setController(DraweeView.java:87)
我需要向 URL 添加其他内容吗?我的印象是可以按原样访问 public 个文件。
我通过将 URL 更改为 "storage-download.googleapis.com...." 解决了这个问题;而不是 "storage.googleapis.com";我真的花了一段时间才发现这一点,因为 Google
没有在任何地方记录它