1

I have PHP code which inserts files into Google Drive. Most of the time it works fine. However I've noticed lately that it will randomly return a 502 error as follows:

  <title>Error 502 (Server Error)!!1</title>
...
  <p><b>502.</b> <ins>That’s an error.</ins>
  <p>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.  <ins>That’s all we know.</ins>

I believe is a temporary error from Google.
It turns out that the file was actually created on Google Drive, so when I retry the request, I end up with a duplicate file.

As it's returned an error instead of a Files resource, how do I get the ID for the new file from Google?

Thanks

Kelly
  • 76
  • 1
  • 8
  • You might want to check [Search for Files](https://developers.google.com/drive/v3/web/search-parameters), where your search a file by name. You can also set it to [Resumable upload](https://developers.google.com/drive/v3/web/manage-uploads#resumable), it is more reliable when uploading large files. It will also lower your chances of getting a duplicate file (see [Best practices](https://developers.google.com/drive/v3/web/manage-uploads#best-practices), to be aware of some best practices related to error handling). Hope this helps. – Mr.Rebot Jan 18 '17 at 16:04
  • Thanks @Mr.Rebot, I forgot about resumable upload! My challenge is I'm transferring files from one cloud to another so I don't have a "filepath" to reference and read chunks from. I am getting the file contents and then writing it straight to Google Drive. Which works ok for small files (with the odd exception of 502 sporadically). To perform resumeable upload, would I need to write the file contents first to some storage and then chunk it down to Google Drive? – Kelly Jan 20 '17 at 12:21

0 Answers0