Constructor. Args: filename: string, Name of the file. mimetype: string, Mime-type of the file. If None then a mime-type will be guessed from the file extension. chunksize: int, File will be uploaded in chunks of this many bytes. Only us
(
self, filename, mimetype=None, chunksize=DEFAULT_CHUNK_SIZE, resumable=False
)
| 573 | |
| 574 | @util.positional(2) |
| 575 | def __init__( |
| 576 | self, filename, mimetype=None, chunksize=DEFAULT_CHUNK_SIZE, resumable=False |
| 577 | ): |
| 578 | """Constructor. |
| 579 | |
| 580 | Args: |
| 581 | filename: string, Name of the file. |
| 582 | mimetype: string, Mime-type of the file. If None then a mime-type will be |
| 583 | guessed from the file extension. |
| 584 | chunksize: int, File will be uploaded in chunks of this many bytes. Only |
| 585 | used if resumable=True. Pass in a value of -1 if the file is to be |
| 586 | uploaded in a single chunk. Note that Google App Engine has a 5MB limit |
| 587 | on request size, so you should never set your chunksize larger than 5MB, |
| 588 | or to -1. |
| 589 | resumable: bool, True if this is a resumable upload. False means upload |
| 590 | in a single request. |
| 591 | """ |
| 592 | self._fd = None |
| 593 | self._filename = filename |
| 594 | self._fd = open(self._filename, "rb") |
| 595 | if mimetype is None: |
| 596 | # No mimetype provided, make a guess. |
| 597 | mimetype, _ = mimetypes.guess_type(filename) |
| 598 | if mimetype is None: |
| 599 | # Guess failed, use octet-stream. |
| 600 | mimetype = "application/octet-stream" |
| 601 | super(MediaFileUpload, self).__init__( |
| 602 | self._fd, mimetype, chunksize=chunksize, resumable=resumable |
| 603 | ) |
| 604 | |
| 605 | def __del__(self): |
| 606 | if self._fd: |