def upload_batch(self): count = random.randint(100, 5000) folder_id = girder_utils.get_random_folder_id(self.client, self.user_id) for i in range(count): with tempfile.NamedTemporaryFile() as temp: slug = self.faker.slug() temp.write(slug) temp.seek(0) r = self.client.post('/api/v1/file', name='api.v1.file', params={ 'parentType': 'folder', 'parentId': folder_id, 'name': temp.name, 'size': len(slug), 'mimeType': 'application/text' }) uploadObj = r.json() if '_id' not in uploadObj: raise Exception( 'After uploading a file chunk, did not receive object with _id. ' 'Got instead: ' + json.dumps(uploadObj)) r = self.client.post('/api/v1/file/chunk/', name='post api.v1.file.chunk', params={ 'offset': 0, 'uploadId': uploadObj['_id'] }, data=temp)
def upload_batch(self): count = random.randint(100,5000) folder_id = girder_utils.get_random_folder_id(self.client, self.user_id) for i in range(count): with tempfile.NamedTemporaryFile() as temp: slug = self.faker.slug() temp.write(slug) temp.seek(0) r = self.client.post('/api/v1/file', name='api.v1.file', params={ 'parentType': 'folder', 'parentId': folder_id, 'name': temp.name, 'size': len(slug), 'mimeType': 'application/text' }) uploadObj = r.json() if '_id' not in uploadObj: raise Exception( 'After uploading a file chunk, did not receive object with _id. ' 'Got instead: ' + json.dumps(uploadObj)) r = self.client.post('/api/v1/file/chunk/', name='post api.v1.file.chunk', params={'offset': 0, 'uploadId': uploadObj['_id']}, data=temp)
def upload_file(self): folder_id = girder_utils.get_random_folder_id(self.client, self.user_id) path, size = random.choice(self.upload_file_paths) offset = 0 slug = self.faker.slug() r = self.client.post('/api/v1/file', name='api.v1.folder', params={ 'parentType': 'folder', 'parentId': folder_id, 'name': slug, 'size': size, 'mimeType': 'application/octet-stream' }) uploadObj = r.json() if '_id' not in uploadObj: raise Exception( 'After uploading a file chunk, did not receive object with _id. ' 'Got instead: ' + json.dumps(uploadObj)) with open(path, 'rb') as stream: while True: chunk = stream.read(min(MAX_CHUNK_SIZE, (size - offset))) if not chunk: break if isinstance(chunk, six.text_type): chunk = chunk.encode('utf8') r = self.client.post('/api/v1/file/chunk', name='post api.v1.file.chunk', params={ 'offset': offset, 'uploadId': uploadObj['_id'] }, data=chunk) uploadObj = r.json() if '_id' not in uploadObj: raise Exception( 'After uploading a file chunk, did not receive object with _id. ' 'Got instead: ' + json.dumps(uploadObj)) offset += len(chunk) self.files.append((uploadObj['_id'], size))
def upload_file(self): folder_id = girder_utils.get_random_folder_id(self.client, self.user_id) path, size = random.choice(self.upload_file_paths) offset = 0 slug = self.faker.slug() r = self.client.post('/api/v1/file', name='api.v1.folder', params={ 'parentType': 'folder', 'parentId': folder_id, 'name': slug, 'size': size, 'mimeType': 'application/octet-stream' }) uploadObj = r.json() if '_id' not in uploadObj: raise Exception( 'After uploading a file chunk, did not receive object with _id. ' 'Got instead: ' + json.dumps(uploadObj)) with open(path, 'rb') as stream: while True: chunk = stream.read(min(MAX_CHUNK_SIZE, (size - offset))) if not chunk: break if isinstance(chunk, six.text_type): chunk = chunk.encode('utf8') r = self.client.post('/api/v1/file/chunk', name='post api.v1.file.chunk', params={'offset': offset, 'uploadId': uploadObj['_id']}, data=chunk) uploadObj = r.json() if '_id' not in uploadObj: raise Exception( 'After uploading a file chunk, did not receive object with _id. ' 'Got instead: ' + json.dumps(uploadObj)) offset += len(chunk) self.files.append((uploadObj['_id'], size))
def create_folder(self): folder_id = girder_utils.get_random_folder_id(self.client, self.user_id) folder_name = self.faker.slug() # Ensure slug is unique for this user # This is slightly over safe seeing as names only need # to be unique with-in each folder, not globally per-user while folder_name in self.folders: folder_name = self.faker.slug() # create folder r = self.client.post('/api/v1/folder', name='api.v1.folder', params={'parentId': folder_id, 'name': folder_name}) r.raise_for_status() self.folders.append(r.json()['name'])
def create_folder(self): folder_id = girder_utils.get_random_folder_id(self.client, self.user_id) folder_name = self.faker.slug() # Ensure slug is unique for this user # This is slightly over safe seeing as names only need # to be unique with-in each folder, not globally per-user while folder_name in self.folders: folder_name = self.faker.slug() # create folder r = self.client.post('/api/v1/folder', name='api.v1.folder', params={ 'parentId': folder_id, 'name': folder_name }) r.raise_for_status() self.folders.append(r.json()['_id'])