3

I want to upload document, file to google docs using Google Apps Engine (python)

any code or link will be appreciated

2 Answers 2

3

See the documentation, but you might 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
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I have already gone from this. I am using a web form to upload my file in Google app engine now i want to store that file in google docs I am finding solution to that problem
1

Solution is with files Upload, You need to read data using below line in python:

function 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))

And also need to modify the gdata python library of Google to achieve this:

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 file directory to google doc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.