Skip to content

Commit

Permalink
Merge pull request #3 from matAlmeida/feat/upload-with-mimetypes
Browse files Browse the repository at this point in the history
Optional mimetypes when uploading files
  • Loading branch information
matAlmeida committed Jun 12, 2020
2 parents 923f2ba + 87d4692 commit 66d16ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -5,6 +5,10 @@
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pygdrive3.svg)
[![Downloads](https://pepy.tech/badge/pygdrive3)](https://pepy.tech/project/pygdrive3)

## Contribute

`If you found any missing feature please create an issue on that github repo or make your pull request.`

## Installing

```sh
Expand Down
14 changes: 8 additions & 6 deletions pygdrive3/service.py
Expand Up @@ -54,16 +54,18 @@ def create_folder(self, name, parent_id=None):

return folder.get('id')

def upload_file(self, name, filePath, folder_id):
fileType = mimetypes.guess_type(filePath)[0]
if fileType == None:
raise NameError("Invalid type or missing suffix!")
def upload_file(self, name, file_path, folder_id, mime_type = None):
fileType = mime_type
if(mime_type == None):
fileType = mimetypes.guess_type(file_path)[0]
if fileType == None:
raise NameError("Invalid type. Provide a mime_type or add the file suffix!")

file_metadata = {
'name': name + '.' + fileType.split('/')[-1],
'name': name,
'parents': [folder_id]
}
media = MediaFileUpload(filePath, mimetype=fileType)
media = MediaFileUpload(file_path, mimetype=fileType)

file = self.drive_service.files().create(
body=file_metadata,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pygdrive3",
version="0.6.0",
version="0.7.0",
author="Matheus Almeida",
author_email="mat.almeida@live.com",
description="Use Google Drive API v3 with a python interface",
Expand Down

0 comments on commit 66d16ab

Please sign in to comment.