从rails中的Google Picker API下载文件 [英] Download file from Google Picker API in rails

查看:72
本文介绍了从rails中的Google Picker API下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Google Picker API ,用于从用户的Google云端硬盘中选择文件。我有关于此API返回的文件的所有元数据。但我坚持如何在我的服务器上下载此文件。

I've used Google Picker API to select a file from user's Google drive. I've all the metadata about the file which is returned by this API. But I'm stuck at how to download this file on my server.

使用以下链接下载文件只能正确下载一些文件而其他文件已损坏:

Using the following link to download the file only downloads some files properly while the others are corrupted:

"https://drive.google.com/uc?export=download&id="+fileid

我正在使用rails版本3.2

I'm using rails version 3.2

任何帮助都将非常感激。谢谢。

Any helps would be much appreciated. Thanks.

推荐答案

这就是我的所作所为:

获取文件我需要从Picker API下载文件的ID,然后将此文件ID传递给google客户端api以获取文档的直接下载URL:

Got the file id of the file I need to download from Picker API, then passed this file id to google client api to get the direct download url of the document:

    gapi.client.request({
        'path': '/drive/v2/files/'+file_id
        'method': 'GET'
        callback: function (responsejs, responsetxt){
            var downloadUrl = responsejs.downloadUrl;
        }
    });

获得此直接下载网址后,我使用rails中的open-uri进行下载和将文件保存在我的服务器上。

After getting this direct download url, I then used the "open-uri" in rails to download and save the file on my server.

这篇关于从rails中的Google Picker API下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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