How to download images with specific size from firebase storage

前端 未结 2 1804
萌比男神i
萌比男神i 2021-01-14 02:39

I am using firebase storage in my android app to store images uploaded by users. all images uploaded are square in shape. I discovered that downloading this

2条回答
  •  情深已故
    2021-01-14 03:23

    I was finally able to download images from firebase storage using MyUrlLoader class

    You see, firebase storage urls look like this

    firebasestorage.googleapis.com/XXXX.appspot.com/Folder%2Image.png?&alt=media&token=XXX
    

    As you can see above, the link already have this special question mark character ? which stands for the start of querying string so when i use CustomImageSize class, another ? was being added so the link was ending up with two ? which made downloading to fail

    firebasestorage.googleapis.com/XXXX.appspot.com/Folder%2Image.png?&alt=media&token=XXX?w=200&h=200
    

    Solution was to remove the ? in my CustomImageSize class. so it ended up like this

        public class CustomImageSize implements MyDataModel {
    
      private String uri;
    
      public CustomImageSize(String uri){
        this.uri = uri;
      }
    
      @Override
      public String buildUrl(int width, int height) {
    
        return uri + "w=" + width + "&h=" + height;
      }
    }
    

    Although it downloaded, am not sure whether entire image was being downloaded or just the custom size one. This is because, i tried to access the image in my browser after correcting the error that was making viewing to fail, but still i was receiving an entire image. not a resized image (w=200&h=200)

提交回复
热议问题