首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gdrive无法下载且无法上载

Gdrive无法下载且无法上载
EN

Stack Overflow用户
提问于 2015-02-17 03:59:19
回答 1查看 51关注 0票数 0

我正在使用GDRive insertFile和RevtrieveAllFiles将文件上传和下载到googledrive。我创建了客户端密码和Id,并修改了凭据。该代码基于代码项目http://www.codeproject.com/KB/WPF/488185/GDrive_Uploader_Sample.zip中的帖子

但它在file.upload中的Utilities.InsertFile中调试失败,并返回exceptionvalue不能为空- uriString。在下载中,它在FileList files = request.Fetch();中失败,

代码语言:javascript
复制
 // First, create a reference to the service you wish to use.
    // For this app, it will be the Drive service. But it could be Tasks, Calendar, etc.
    // The CreateAuthenticator method is passed to the service which will use that when it is time to authenticate
    // the calls going to the service.
    _service = new DriveService(CreateAuthenticator());

    // Open a dialog box for the user to pick a file.
    OpenFileDialog dialog = new OpenFileDialog();
    dialog.AddExtension = true;
    dialog.DefaultExt = ".txt";
    dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
    dialog.Multiselect = false;
    dialog.ShowDialog();


    File body = new File();
    body.Title = System.IO.Path.GetFileName(dialog.FileName);
    body.Description = "A test document";
    body.MimeType = "text/plain";

    System.IO.Stream fileStream = dialog.OpenFile();
    byte[] byteArray = new byte[fileStream.Length];
    fileStream.Read(byteArray, 0, (int)fileStream.Length);

    System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

    // Get a listing of the existing files...
    List<File> fileList = Utilities.RetrieveAllFiles(_service);

    // Set a flag to keep track of whether the file already exists in the drive
    bool fileExists = false;

    foreach (File item in fileList)
    {
        if (item.Title == body.Title)
        {
            // File exists in the drive already!
            fileExists = true;
            MessageBoxResult result = System.Windows.MessageBox.Show("The file you picked already exists in your Google Drive. Do you wish to overwrite it?", "Confirmation", MessageBoxButton.YesNoCancel);
            if (result == MessageBoxResult.Yes)
            {

                // Yes... overwrite the file
                Utilities.UpdateFile(_service, item.Id, item.Title, item.Description, item.MimeType, dialog.FileName, true);
                List<File> allFiles = Utilities.RetrieveAllFiles(_service);

            }

            else if (result == MessageBoxResult.No)
            {

                // MessageBoxResult.No code here
              File f=             Utilities.insertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
            }

            else
            {

                // MessageBoxResult.Cancel code here
                return;
            }
            break;
        }
    }

    // Check to see if the file existed. If not, it is a new file and must be uploaded.
    if (!fileExists)
    {
      File file=  Utilities.insertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
      var list = Utilities.RetrieveAllFiles(_service);

    }

    System.Windows.MessageBox.Show("Upload Complete");
EN

回答 1

Stack Overflow用户

发布于 2015-02-26 04:30:46

打开gdrive并将sdk设置为On。这将使应用程序能够访问gdrive帐户

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28549380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档