谷歌推动Android阿比要求尺寸图像下载 [英] Google drive Android Api requested dimension image download

查看:150
本文介绍了谷歌推动Android阿比要求尺寸图像下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个谷歌云端硬盘Android应用,我应该能够从谷歌下载驱动器调整大小的图像。

I'm trying to create a Google drive android app where I should be able to download resized images from Google drive.

同类产品性能的问题。
假设我从我的电脑上传的1080px一个形象,我现在想下载该图像在我的Andr​​oid手机不支持1080px的形象,所以会发生什么是图像先被下载则其按我的器件尺寸大小。但是,这其实是时间和数据的浪费。

Its kind of a performance issue. Suppose i have uploaded a image of 1080px from my computer, now I wish to download that image in my Android phone which doesn't support 1080px image, so what happens is the image first gets downloaded then its resized as per my device dimensions. But this is actually wastage of time and data.

为什么要下载一个1080px图像时,我只能说明可能会像480像素或720像素的图像。

Why to download a 1080px image when I can only show may be like 480px or 720px image.

我使用谷歌云端硬盘API,但我想知道是否有一些参数或者一些东西,我们可以从电话中传递,使我们得到只下载了调整后的图像。

I'm using Google drive api but I would like to know whether there is some parameter or something which we can pass from phone so that we get to download the resized image only.

按我的搜索,
链接

有就是这个部分下载,我可以给一个字节范围,但我并不想下载文件的特定部分,我想下载整个图像文件中调整大小的格式。

There is this Partial download where I can give a range of bytes but I'm not trying to download a particular portion of a file, I want to download the whole image file in a resized format.

任何想法,线索将是非常有益的。

Any ideas, clues will be very helpful.

感谢

推荐答案

答案适用于的RESTful阿比时,因为 GDAA 的不具有'thumbnailLink'的功能截至今天(2月14 2015年)。

The answer applies to the RESTful Api, since GDAA does not have a 'thumbnailLink' functionality as of today (Feb 14. 2015).

我用这个code片段下载缩小的图像和缩略图:

I use this code snippet to download reduced images and thumbnails:

/**
 * get file contents, specifically image. The thmbSz, if not zero, it attempts to 
 * retrieve an image thumbnail that fits into a square envelope of thmbSz pixels
 * @param rsId   file id
 * @param thmbSz reduced size envelope (optional value, 0 means full size image / file)
 *   (tested with: 128,220,320,400,512,640,720,800,1024,1280,1440,1600)
 * @return       file's content  / null on fail
 */
com.google.api.services.drive.Drive mGOOSvc;
...
static byte[] read(String rsId, int thmbSz) {
  byte[] buf = null;
  if (rsId != null) try {
    File gFl = (thmbSz == 0) ?
      mGOOSvc.files().get(rsId).setFields("downloadUrl").execute() :
      mGOOSvc.files().get(rsId).setFields("thumbnailLink").execute();
    if (gFl != null){
      String strUrl;
      if (thmbSz == 0)
         strUrl = gFl.getDownloadUrl();
      else {
         strUrl = gFl.getThumbnailLink();
         if (! strUrl.endsWith("s220")) return null; //--- OOPS ------------>>>
         strUrl = strUrl.substring(0, strUrl.length()-3) + Integer.toString(thmbSz);
      }
      InputStream is = mGOOSvc.getRequestFactory()
                 .buildGetRequest(new GenericUrl(strUrl)).execute().getContent();
      buf = UT.is2Bytes(is);
    }
  } catch (Exception e) { UT.le(e); }
  return buf;
}

我有一个与几个尺寸(见方法头),这是我从的这里的Picasa文档。

你看,'thumbnailLink'的形式

See, the 'thumbnailLink' has the form of

https://lh4.googleusercontent.com/R1Pi...blahblah...08qIhg=s220

和通过在端改变'220'到下列值之一:

and by changing the '220' at the end to one of these values:

128,220,320,400,512,640,720,800,1024,1280,1440,1600

128,220,320,400,512,640,720,800,1024,1280,1440,1600

我设法拉请求大小的图像(让服务器来减少它)。

I managed to pull the image of the requested size (letting the server to reduce it).

免责声明:

这不是一个文档的功能,所以它是一个黑客。我也承认,一个更强大的版本,不应该依赖于寻找S220,但很可能= sNUMBERpatttern。
祝你好运。

It is not a documented feature, so it is a HACK. I also admit that a more robust version should not rely on finding "s220", but probably "=sNUMBER" patttern. Good luck.

这篇关于谷歌推动Android阿比要求尺寸图像下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆