title: 404 on update file with fileID on google drive api
body: <p>I have seen this question asked a few times, but none of the answers were helpful. Unless it is a 'user permission' problem in which case I don't know how to handle it.</p>
  <p><strong>Context</strong></p>
  <ul>
  <li>Created a new file (from a Lua app, so using REST)
  <ul>
  <li>used ?uploadType=resumable</li>
  <li>from the return, captured responseHeaders['X-GUploader-UploadID'] and response['id'], same result for both</li>
  </ul>
  </li>
  <li>File exists, can see it on Google Drive</li>
  </ul>
  <p>Then, try to update, and I get 404 Not Found. Here is the Lua code:</p>
  <p><strong>Code</strong></p>
  <pre><code>local url = &quot;https://www.googleapis.com/upload/drive/v3/files&quot;
  </code></pre>
  <p>[userStateID has the id captured above]</p>
  <pre><code>url = url..&quot;/&quot;.._G.lobal.userStateID..&quot;/?uploadType=media&quot;
  url = url..&quot;/?uploadType=media&amp;upload_id=&quot;.._G.lobal.userStateID
  </code></pre>
  <p>[I tried both variations above, same result]</p>
  <pre><code>resbody = stuff
  
  local headers = {['Content-type'] = &quot;application/json&quot;,
    Authorization=oauth,
    ['user-agent'] = &quot;SilkRoad &quot;.._G.VERSION,
    ['X-Upload-Content-Type']=&quot;application/text; charset=utf-8&quot;,
    ['Content-Length']=string.len(resbody)
  }
  local params = {headers=headers,body=resbody}
  network.request(url, &quot;PUT&quot;, uploadListener, params )
  </code></pre>
  <p>[async network call in lua]</p>
  <p><strong>Result</strong></p>
  <p>{&quot;responseHeaders&quot;:{&quot;Content-Type&quot;:&quot;text/html; charset=UTF-8&quot;,&quot;X-GUploader-UploadID&quot;:&quot;ABg5-UxILyJZKOABmdvQ2tDrsXrRTHY-pljfWSk67vcKyzcSoR28BoMjHG5gFi0a3GLUPVSU3T5bBvqlnK5qG0-lNEOc0Tp4vQ&quot;,&quot;Vary&quot;:&quot;Origin, X-Origin&quot;,&quot;Date&quot;:&quot;Sun, 30 May 2021 20:52:17 GMT&quot;,&quot;Alt-Svc&quot;:&quot;h3-29=&quot;:443&quot;; ma=2592000,h3-T051=&quot;:443&quot;; ma=2592000,h3-Q050=&quot;:443&quot;; ma=2592000,h3-Q046=&quot;:443&quot;; ma=2592000,h3-Q043=&quot;:443&quot;; ma=2592000,quic=&quot;:443&quot;; ma=2592000; v=&quot;46,43&quot;&quot;,&quot;Content-Length&quot;:&quot;9&quot;,&quot;Server&quot;:&quot;UploadServer&quot;},&quot;responseType&quot;:&quot;text&quot;,&quot;phase&quot;:&quot;ended&quot;,&quot;bytesEstimated&quot;:9,&quot;response&quot;:&quot;Not Found&quot;,&quot;name&quot;:&quot;networkRequest&quot;,&quot;bytesTransferred&quot;:9,&quot;status&quot;:404,&quot;url&quot;:&quot;https://www.googleapis.com/upload/drive/v3/files/?uploadType=media&amp;upload_id=ABg5-UxG8zBq7ARLKAd7cE0FB2z9NG1Sv8gKlnH_QjDqluSOaun5oRRI3h7fXHHn1KqEW1DolBkMmh4GlgwgOGl9NOc&quot;,&quot;isError&quot;:false,&quot;requestId&quot;:&quot;&lt;type 'userdata' is not supported by JSON.&gt;&quot;}</p>
  <p>There is no 'user' to give privileges. But perhaps to use this mechanism, to update any file my app creates I have to then ask the user to go to their Drive and change permissions? That doesn't sound right. Maybe a flag I need to put on the metadata?</p>
  <p>The 'X-GUploader-UploadID' is not documented, but same result if I use response['id']. I have verified that the id in Google Drive (for sharing) is the same id returned in response['id']. But says Not found when I use it for update.</p>
  <p>BTW, just trying to update by reusing the resume URL or this variation:</p>
  <pre><code>https://www.googleapis.com/upload/drive/v3/files?upload_id=...
  </code></pre>
  <p>has an odd result: no error, but the file is not updated.</p>
  <p>Using PATCH instead of PUT on the original update has also a curious effect -- no error, but updates the file to empty. So perhaps that is the secret but I have to figure out how to pass the body correctly?</p>