简体   繁体   English

使用C#在ASP.Net中使用Google Drive API将文件上传到Google云端硬盘

[英]Upload Files to Google Drive using Google Drive API in ASP.Net with C#

Upload Files to Google Drive using Google Drive API in ASP.Net with C#. 使用带有C#的ASP.Net中的Google Drive API将文件上传到Google云端硬盘。 Initially I have completed all the steps that needs to create the API with google and get Client ID and Client Secret. 最初,我已经完成了使用google创建API并获取客户端ID和客户端密钥所需的所有步骤。 And then used this code. 然后使用此代码。

protected void Page_Load(object sender, EventArgs e)
{
    connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
    con = new SqlConnection(connStr);
    cm = new ClassMain();
    cmd = new SqlCommand();
    google();
}
protected void UploadFile(object sender, EventArgs e)
{
    Session["File"] = FileUpload1.PostedFile;
    GoogleConnect.Authorize("https://www.googleapis.com/auth/drive.file");

}
protected void google()
{
    GoogleConnect.ClientId = "<Client ID>";
    GoogleConnect.ClientSecret = "<Client Secret>";
    GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
    GoogleConnect.API = EnumAPI.Drive;
    if (!string.IsNullOrEmpty(Request.QueryString["code"]))
    {
        string code = Request.QueryString["code"];
        string json = GoogleConnect.PostFile(code, (HttpPostedFile)Session["File"], "");
        GoogleDriveFile file = (new JavaScriptSerializer()).Deserialize<GoogleDriveFile>(json);           
    }
    if (Request.QueryString["error"] == "access_denied")
    {
        ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
    }
}

It will work properly for small size of file like 1 to 10 MB, If File size Increase then give error- 它适用于1到10 MB的小文件,如果文件大小增加,则给出错误 -

The webpage at http://localhost:1762/ChangeADCUploadedNewded/BlankPage.aspx?code=4%2fAk03HmpOQsV5Na_pM2fs5vzdfJTa2yoMzWAy-lD_CVE might be temporarily down or it may have moved permanently to a new web address. http:// localhost:1762 / ChangeADCUploadedNewded / BlankPage.aspx?code = 4%2fAk03HmpOQsV5Na_pM2fs5vzdfJTa2yoMzWAy-lD_CVE的网页可能暂时关闭,或者可能已永久移动到新的网址。

resolve the error. 解决错误。

403-Invalid Credential error is not come at this time. 403-此时未出现无效的凭据错误。

I did a little research and found that Google used to have the 10MB limit for uploads as you can see here: https://productforums.google.com/forum/#!topic/drive/N9Ruvnf0Jx8 but they increased that limit last year to 1TB. 我做了一些研究,发现谷歌曾经有10MB的上传限制,你可以在这里看到: https//productforums.google.com/forum/#!topic / drive / N9Ruvnf0Jx8但他们去年增加了这个限制1TB。 The only limitation that I was able to find for files larger than 10MB is when the uploaded file needs to be converted to a Google Doc, Sheet or Slides. 我能够找到大于10MB的文件的唯一限制是上传的文件需要转换为Google Doc,Sheet或Slides。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM