【问题标题】:Download file from Google Drive via rest api using gzip compression使用 gzip 压缩通过 rest api 从 Google Drive 下载文件
【发布时间】:2015-08-19 06:09:22
【问题描述】:

我正在使用以下代码从 Google 云端硬盘下载公开共享的文件。它工作正常。

InputStream input = null;
OutputStream output = null;

HttpURLConnection httpsURLConnectionToGoogleDrive = (HttpURLConnection) new URL(downloadUrl).openConnection();
httpsURLConnectionToGoogleDrive.connect();

long fileLength = httpsURLConnectionToGoogleDrive.getContentLength();
input = httpsURLConnectionToGoogleDrive.getInputStream();

byte data[] = new byte[MediaHttpUploader.MINIMUM_CHUNK_SIZE];
int count;
while ((count = input.read(data)) != -1) {
    // allow canceling with back button
    if (isCancelled()) {
        input.close();
        return null;
    }
    total += count;
    log("Received Up To : "+ total + " ("+ count +") ");
    // publishing the progress....
    if (fileLength > 0) { // only if total length is known
        publishProgress((int) (total * 100 / fileLength));
    }
    output.write(data, 0, count);
}

现在,我想添加 gzip 压缩以节省带宽。从this reference 我添加了以下代码:-

httpsURLConnectionToGoogleDrive.setRequestProperty("Accept-Encoding", "gzip");
httpsURLConnectionToGoogleDrive.setRequestProperty("User-Agent", "my program (gzip)");

但我无法让它工作。我被困在这里。怎么办?

【问题讨论】:

    标签: android google-drive-api gzip


    【解决方案1】:

    Drive API 默认已将请求作为 gzip 进行管理,因此您无需付出额外的努力。仅当您要创建自己的库时,才应指定 gzip 的标头。

    【讨论】:

    • 我正在使用 Drive rest API。所以需要我们自己处理,我猜
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    相关资源
    最近更新 更多