Google Drive And LOAD DATA INFILE

Hi David,

You’re quite right, the MySQL client library requires a real local filename, and the Google Drive file is not local. Thankfully, that’s easy to fix. Just write the contents of that Google Drive file into a local file, then use that:

import random, os

# Generate a temporary random local file name
tmp_name = "/tmp/%s" % "".join([random.choice("0123456789abcdef") for x in range(32)])

# Read the Google Drive file into the temporary local file
with open(tmp_name, 'wb') as f:
  f.write(app_files.my_file.get_bytes())

### Do whatever you need to do with the local file
### ...

# Delete the local file now we're finished with it
os.unlink(tmp_name)

Does that do what you want?

1 Like