question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After update to API v3 Update won't work.

See original GitHub issue

Hello. I use method to update file and it works fine. After I’ve updated library to API v3 and changed part of the code, it stopped working. I haven’t get any Exception but file on Google Drive hadn’t changed. Similar method with _service.Files.Create works fine.

public static File updateFile(DriveService _service, string _uploadFile, string _parent, string _fileId,      string Description)
    {
        if (System.IO.File.Exists(_uploadFile))
        {
            File body = new File();
            body.Name = System.IO.Path.GetFileName(_uploadFile);
            body.Description = Description;
            body.MimeType = GetMimeType(_uploadFile);
            body.Parents = new List<string> { _parent };

            byte[] byteArray = System.IO.File.ReadAllBytes(_uploadFile);
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
            try
            {
                FilesResource.UpdateMediaUpload request = _service.Files.Update(body, _fileId, stream, GetMimeType(_uploadFile));
                request.Upload();
                return request.ResponseBody;
            }
            catch (Exception)
            {
                return null;
                throw;
            }
        }
        else
        {
            return null;
        }
    }

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
erickoledadevrelcommented, Feb 2, 2016

This appears to be working as intended. As per the documentation, request.Upload() returns an IUploadProgress which has en Exception field which contains the exception, instead of throwing it. In this case an exception is being thrown, because in Drive v3 Update() requests use patch semantics and can only contain writeable fields in the File body. In your case you are first (unnecessarily) fetching the existing File object, which contains read-only fields.

0reactions
giorgiolamicommented, Nov 14, 2020

@erickoledadevrel thanks a lot!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Github API v3: Update file not working (404)
After editing the file, I try to update the file. On my submit I post the following using jQuery: var postData = {...
Read more >
API v3 REST - Add WorkLog is broken after update.
The script I am using is pretty similar to yours but I am noticing that $SdpUri + "/api/v3/worklog" is not working when viewing...
Read more >
Re: API version update
It looks like you received this communication because a V3 API key was previously generated within your account, but based on the code...
Read more >
Update project rest API is not working
The update project rest api doesn't seem to be working. First, the documentation says "all parameters are optional in the body of the...
Read more >
v3 Deals update returns no properties found to update
v3 Deals update returns no properties found to update. I am working on integration with Hubspot using v3 API. I am trying to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found