|
3 | 3 | import os |
4 | 4 | from datetime import datetime |
5 | 5 | from functools import partial |
| 6 | +from io import IOBase |
| 7 | +from os import PathLike |
6 | 8 | from os.path import isfile, join |
7 | 9 | from typing import IO, AnyStr, Callable |
8 | 10 |
|
@@ -383,17 +385,12 @@ def _modify_query(request: RequestOptions) -> None: |
383 | 385 | self.context.add_query(qry).before_execute(_modify_query) |
384 | 386 | return return_type |
385 | 387 |
|
386 | | - def upload_file(self, path_or_file: str | IO) -> DriveItem: |
387 | | - """Uploads a file""" |
388 | | - if isinstance(path_or_file, IO): |
389 | | - content = path_or_file.read() |
390 | | - name = os.path.basename(path_or_file.name) |
391 | | - return self.upload(name, content) |
392 | | - else: |
393 | | - with open(path_or_file, "rb") as f: |
394 | | - content = f.read() |
395 | | - name = os.path.basename(path_or_file) |
396 | | - return self.upload(name, content) |
| 388 | + def upload_file(self, path_or_file: str | PathLike | IOBase) -> DriveItem: |
| 389 | + """Uploads a file (up to ~4MB; use resumable_upload for larger files).""" |
| 390 | + if isinstance(path_or_file, IOBase): |
| 391 | + return self.upload(os.path.basename(path_or_file.name), path_or_file.read()) |
| 392 | + with open(path_or_file, "rb") as f: |
| 393 | + return self.upload(os.path.basename(str(path_or_file)), f.read()) |
397 | 394 |
|
398 | 395 | def upload_folder(self, path: str, file_uploaded: Callable[["DriveItem"], None] | None = None) -> DriveItem: |
399 | 396 | """Uploads a folder""" |
|
0 commit comments