Skip to content
This repository was archived by the owner on Jul 22, 2021. It is now read-only.
This repository was archived by the owner on Jul 22, 2021. It is now read-only.

Google Api Drive Issue while downloading a file #222

@bhavnish07

Description

@bhavnish07

Google api Client don't give me latest version of file stored on google drive. It will always give me older version of file

Any help in this will be helpful
Thanks in Advance

 def get_drive_service(self):
        if not self.env.user.oauth_access_token:
            raise UserError(_("Please Add google access token to your account for uploading files to google drive"))
        cred = Credentials(self.env.user.oauth_access_token)
        service = build("drive", "v3", credentials=cred)
        return service
  def convert_to_doc(self):
        if not self.google_drive_link:
            raise ValidationError(_("Please Add url of file"))
        file_id = self._get_key_from_url(self.google_drive_link)
        service = self.get_drive_service()
        with google_service_context() as manager:
            file = service.files().get(fileId=file_id).execute()
        request = service.files().get_media(fileId=file_id)
        fh = io.BytesIO()
        with google_service_context() as manager:
            downloader = MediaIoBaseDownload(fh, request)
        done = False
        while done is False:
            with google_service_context() as manager:
                status, done = downloader.next_chunk()
        fh.seek(0)
        self.write(
            {'doc_type': 'upload_attachment', 'content_binary': base64.b64encode(fh.read()), 'name': file.get('name')})
        return self

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions