Hello everyone,
I am having a bit of a problem uploading a pdf file to Google drive. I am trying to create a form which also entails the user uploading a document with the .pdf extension.
So far I have this, but obviously it does´s work:
I haven’t used pydrive before, but I think something like this should work. The basic issue is that an uploaded file is just in-memory, and not saved to disk, but you can use a temporary file to get around this.
from tempfile import NamedTemporaryFile
pm = st.file_uploader("Upload your file", type=“pdf”)
with NamedTemporaryFile() as f:
f.write(pm.getvalue())
gauth.LocalWebserverAuth()
gfile = drive.CreateFile({‘parents’: [{'id': drive_key}], "title": pm.name})
gfile.SetContentFile(f.name)
gfile.Upload()