Using the Google App Engine to load a document into Google documents (python)

I want to upload a document, file to Google documents using Google Apps Engine (python)

any code or link will be appreciated

+3
source share
2 answers

Solution with Upload files, you need to read the data using the following line in python:

to read file size

def getSize(self,fileobject):
  fileobject.seek(0,2) # move the cursor to the end of the file
  size = fileobject.tell()
  return size



f = self.request.POST.get('fname').file

media = gdata.data.MediaSource(file_handle=f.read(), content_type=gdata.docs.service.SUPPORTED_FILETYPES[ext], content_length=self.getSize(self.request.POST.get('fname').file))

It is also necessary to modify the python gdata library for Google:

client.py:

in def upload_file

replace:

while not entry:
 entry = self.upload_chunk(start_byte, self.file_handle.read(self.chunk_size))
 start_byte += self.chunk_size

WITH

while not entry:
  entry = self.upload_chunk(start_byte, self.file_handle)
  start_byte += self.chunk_size

And you can upload the file directory in google doc

+1
source

See the documentation , but you can try something like:

ms = gdata.MediaSource(file_path='/path/to/your/test.doc',  content_type=gdata.docs.service.SUPPORTED_FILETYPES['DOC'])
entry = gd_client.Upload(ms, 'MyDocTitle')
print 'Document now accessible online at:', entry.GetAlternateLink().href
+3
source

Source: https://habr.com/ru/post/1750967/


All Articles