def _upload_form_encoded(self, url, filepath, shard_size, start_pos, read_size=1024, callback=None): """ Streams file from disk and uploads it. :param url: API endpoint as URL to upload to :param filepath: Path to file as string :return: requests.Response """ validpath = self.check_path(filepath) if shard_size == 0: shard_size = SizeHelpers.mib_to_bytes(250) shard = ShardFile(validpath, 'rb', shard_size=shard_size, start_pos=start_pos, read_size=read_size, callback=callback) m = MultipartEncoder({'file': ('file', shard)}) headers = {'Content-Type': m.content_type} return requests.post(url, data=m, headers=headers)
def test_init_callback(self): test_shard = ShardFile(self.testfile, 'rb', callback=callback) self.assertEqual(test_shard.callback, callback)
def test_context_manager(self): with ShardFile(self.testfile) as shard: self.assertTrue(isinstance(shard, ShardFile)) self.new_shard = shard self.assertTrue(self.new_shard._f_obj.closed) del self.new_shard
def setUp(self): self.testfile = 'tests/one-meg.testfile' self.shard = ShardFile(self.testfile, 'rb')