简体   繁体   English

从GoogleDriveFile pydrive的内容获取类似对象的文件

[英]Get file like object from contents of GoogleDriveFile pydrive

Here are the docs: 这里是文档:

FetchContent(*args, **kwargs)

Download file's content from download_url. download_url.下载文件的内容download_url.

Raises: 筹款:

ApiRequestError, FileNotUploadedError, FileNotDownloadableError

I tried supplying GoogleDriveFile.metadata['selfLInk'] and it didn't work.... there also a GoogleDriveFile.get method which has 1 argument (i got from errors) I have no idea what that argument is or what it does.. Also GoogleDriveFile.content is none 我尝试提供GoogleDriveFile.metadata['selfLInk'] ,但没有用...。还有一个GoogleDriveFile.get method ,它有1个参数(我从错误中得到)我不知道该参数是什么或它做什么..另外GoogleDriveFile.content也没有

Just trying to do this: 只是想这样做:

data=GoogleDriveFile.getcontent()
z=data.read(1024)
while z:
     newdata=do stuff(z)
     localfile.write(newdata)
     z=data.read(1024)
z.close()
localfile.close()

I think pydrive uses the v2 api, I tried doing something liek this: https://youtu.be/-7YH6rdR-tk?t=573 How do I implement that with pydrive? 我认为pydrive使用了v2 api,我尝试做些类似的事情: https ://youtu.be/-7YH6rdR-tk?t=573如何使用pydrive实现它? you can see the data part where he writes data to local file. 您可以看到他将数据写入本地文件的数据部分。

drive=login()#

z=drive
an='file.ext' #set permission to anyoen with link cna download
zz = z.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for f in zz:
    if f['title']==an:
        ww=f.metadata['downloadUrl']
        print ww
        print dir(f.FetchContent(ww))
        break
import sys
sys.exit()

['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

您调用FetchContent(),然后bytesIO对象为.content

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM