# Get URL where component can be downloadedserver_location=session.get('Location',ftrack_api.symbol.SERVER_LOCATION_ID)note_component=session.query('NoteComponent').first()component=note_component['component']url=server_location.get_url(note_component['component'])# Or, download the file using disk accessor.defdownload_component(target_directory,component):'''Download component to *target_directory*. Note: will overwrite data if a file with the same name already exists within the directory. '''importfunctoolsdisk_accessor=ftrack_api.accessor.disk.DiskAccessor(target_directory)target_file_name=u'{}{}'.format(component['name'],component['file_type'])server_location=session.get('Location',ftrack_api.symbol.SERVER_LOCATION_ID)source_data=server_location.accessor.open(server_location.get_resource_identifier(component),'rb')target_data=disk_accessor.open(target_file_name,'wb')chunked_read=functools.partial(source_data.read,ftrack_api.symbol.CHUNK_SIZE)forchunkiniter(chunked_read,''):target_data.write(chunk)target_data.close()source_data.close()# Change to destination foldertarget_directory='/path/to/backup/directory'# Query 10 first note componentsnote_components=session.query('select component.name, component.file_type from NoteComponent limit 10')fornote_componentinnote_components:component=note_component['component']download_component(target_directory,component)
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.