onedrive/api_v5.py
def put( self, path_or_tuple, folder_id='me/skydrive',
			overwrite=None, downsize=None, bits_api_fallback=True ):
		'''Upload a file (object), possibly overwriting (default behavior)
				a file with the same "name" attribute, if it exists.

			First argument can be either path to a local file or tuple
				of "(name, file)", where "file" can be either a file-like object
				or just a string of bytes.

			overwrite option can be set to False to allow two identically-named
				files or "ChooseNewName" to let OneDrive derive some similar
				unique name. Behavior of this option mimics underlying API.

			downsize is a true/false API flag, similar to overwrite.

			bits_api_fallback can be either True/False or an integer (number of
				bytes), and determines whether method will fall back to using BITS API
				(as implemented by "put_bits" method) for large files. Default "True"
				(bool) value will use non-BITS file size limit (api_put_max_bytes, ~100 MiB)
				as a fallback threshold, passing False will force using single-request uploads.'''
		api_overwrite = self._translate_api_flag(overwrite, 'overwrite', ['ChooseNewName'])
		api_downsize = self._translate_api_flag(downsize, 'downsize')
		name, src = self._process_upload_source(path_or_tuple)

		if not isinstance(bits_api_fallback, (int, float, long)):
			bits_api_fallback = bool(bits_api_fallback)
		if bits_api_fallback is not False:
			if bits_api_fallback is True: bits_api_fallback = self.api_put_max_bytes
			src.seek(0, os.SEEK_END)
			if src.tell() >= bits_api_fallback:
				if bits_api_fallback > 0: # not really a "fallback" in this case
					log.info(
						'Falling-back to using BITS API due to file size (%.1f MiB > %.1f MiB)',
						*((float(v) / 2**20) for v in [src.tell(), bits_api_fallback]) )
				if overwrite is not None and api_overwrite != 'true':
					raise NoAPISupportError( 'Passed "overwrite" flag (value: {!r})'
						' is not supported by the BITS API (always "true" there)'.format(overwrite) )
				if downsize is not None:
					log.info( 'Passed "downsize" flag (value: %r) will not'
						' be used with BITS API, as it is not supported there', downsize )
				file_id = self.put_bits(path_or_tuple, folder_id=folder_id) # XXX: overwrite/downsize
				return self.info(file_id)

		# PUT seem to have better support for unicode
		#  filenames and is recommended in the API docs, see #19.
		# return self( self._api_url_join(folder_id, 'files'),
		# 	dict(overwrite=api_overwrite, downsize_photo_uploads=api_downsize),
		# 	method='post', files=dict(file=(name, src)) )
		return self( self._api_url_join(folder_id, 'files', name),
			dict(overwrite=api_overwrite, downsize_photo_uploads=api_downsize),
			data=src, method='put', auth_header=True )
def put( self, path_or_tuple, folder_id='me/skydrive',
			overwrite=None, downsize=None, bits_api_fallback=True ):
		'''Upload a file (object), possibly overwriting (default behavior)
				a file with the same "name" attribute, if it exists.

			First argument can be either path to a local file or tuple
				of "(name, file)", where "file" can be either a file-like object
				or just a string of bytes.

			overwrite option can be set to False to allow two identically-named
				files or "ChooseNewName" to let OneDrive derive some similar
				unique name. Behavior of this option mimics underlying API.

			downsize is a true/false API flag, similar to overwrite.

			bits_api_fallback can be either True/False or an integer (number of
				bytes), and determines whether method will fall back to using BITS API
				(as implemented by "put_bits" method) for large files. Default "True"
				(bool) value will use non-BITS file size limit (api_put_max_bytes, ~100 MiB)
				as a fallback threshold, passing False will force using single-request uploads.'''
		api_overwrite = self._translate_api_flag(overwrite, 'overwrite', ['ChooseNewName'])
		api_downsize = self._translate_api_flag(downsize, 'downsize')
		name, src = self._process_upload_source(path_or_tuple)

		if not isinstance(bits_api_fallback, (int, float, long)):
			bits_api_fallback = bool(bits_api_fallback)
		if bits_api_fallback is not False:
			if bits_api_fallback is True: bits_api_fallback = self.api_put_max_bytes
			src.seek(0, os.SEEK_END)
			if src.tell() >= bits_api_fallback:
				if bits_api_fallback > 0: # not really a "fallback" in this case
					log.info(
						'Falling-back to using BITS API due to file size (%.1f MiB > %.1f MiB)',
						*((float(v) / 2**20) for v in [src.tell(), bits_api_fallback]) )
				if overwrite is not None and api_overwrite != 'true':
					raise NoAPISupportError( 'Passed "overwrite" flag (value: {!r})'
						' is not supported by the BITS API (always "true" there)'.format(overwrite) )
				if downsize is not None:
					log.info( 'Passed "downsize" flag (value: %r) will not'
						' be used with BITS API, as it is not supported there', downsize )
				file_id = self.put_bits(path_or_tuple, folder_id=folder_id) # XXX: overwrite/downsize
				return self.info(file_id)

		# PUT seem to have better support for unicode
		#  filenames and is recommended in the API docs, see #19.
		# return self( self._api_url_join(folder_id, 'files'),
		# 	dict(overwrite=api_overwrite, downsize_photo_uploads=api_downsize),
		# 	method='post', files=dict(file=(name, src)) )
		return self( self._api_url_join(folder_id, 'files', name),
			dict(overwrite=api_overwrite, downsize_photo_uploads=api_downsize),
			data=src, method='put', auth_header=True )
Upload a file (object), possibly overwriting (default behavior)
				a file with the same "name" attribute, if it exists.

			First argument can be either path to a local file or tuple
				of "(name, file)", where "file" can be either a file-like object
				or just a string of bytes.

			overwrite option can be set to False to allow two identically-named
				files or "ChooseNewName" to let OneDrive derive some similar
				unique name. Behavior of this option mimics underlying API.

			downsize is a true/false API flag, similar to overwrite.

			bits_api_fallback can be either True/False or an integer (number of
				bytes), and determines whether method will fall back to using BITS API
				(as implemented by "put_bits" method) for large files. Default "True"
				(bool) value will use non-BITS file size limit (api_put_max_bytes, ~100 MiB)
				as a fallback threshold, passing False will force using single-request uploads.