MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / upload_new_file

Method upload_new_file

python/collaboration/project.py:746–829  ·  view source on GitHub ↗

Upload a file to the project, creating a new File and pulling it .. note:: If the project has not been opened, it will be opened upon calling this. :param target: Path to file on disk or BinaryView/FileMetadata object of already-opened file :param parent_folder: Parent fo

(
			self,
			target: Union[str, PathLike, 'BinaryView', 'FileMetadata'],
			parent_folder: Optional['folder.RemoteFolder'] = None,
			progress: 'util.ProgressFuncType' = util.nop,
			open_view_options = None)

Source from the content-addressed store, hash-verified

744 return core.BNRemoteProjectCanUserAdmin(self._handle, username)
745
746 def upload_new_file(
747 self,
748 target: Union[str, PathLike, 'BinaryView', 'FileMetadata'],
749 parent_folder: Optional['folder.RemoteFolder'] = None,
750 progress: 'util.ProgressFuncType' = util.nop,
751 open_view_options = None) -> 'file.RemoteFile':
752 """
753 Upload a file to the project, creating a new File and pulling it
754
755 .. note:: If the project has not been opened, it will be opened upon calling this.
756
757 :param target: Path to file on disk or BinaryView/FileMetadata object of
758 already-opened file
759 :param parent_folder: Parent folder to place the uploaded file in
760 :param progress: Function to call for progress updates
761 :return: Created File object
762 :raises: RuntimeError if there was an error
763 """
764 if not self.open():
765 raise RuntimeError("Failed to open project")
766
767 if isinstance(target, FileMetadata):
768 if target.has_database:
769 return databasesync.upload_database(target, self, parent_folder=parent_folder, progress=progress)
770 else:
771 target = target.raw
772
773 if isinstance(target, BinaryView):
774 maybe_bv = target
775 target = maybe_bv.file.original_filename
776 else:
777 # Convert PathLike to string
778 if isinstance(target, (Path,)):
779 target = target.resolve()
780
781 target = str(target)
782
783 # Argument is a path, try opening it:
784 try:
785 if open_view_options is None:
786 open_view_options = {}
787 maybe_bv = load(
788 target, progress_func=util.split_progress(progress, 0, [0.25, 0.75]), **open_view_options)
789 except Exception as e:
790 raise RuntimeError("Could not upload view: " + str(e))
791
792 with tempfile.TemporaryDirectory() as temp_dir:
793 with maybe_bv as bv:
794 # Can't open, can't upload
795 if not bv:
796 raise RuntimeError("Could not open file at path for uploading")
797
798 # If it is backed by a database, just upload that
799 metadata = bv.file
800 if metadata.has_database:
801 uploaded = databasesync.upload_database(
802 metadata, self, parent_folder=parent_folder, progress=util.split_progress(progress, 1, [0.25, 0.75]))
803 return uploaded

Callers 3

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 9

openMethod · 0.95
log_infoFunction · 0.85
upload_databaseMethod · 0.80
resolveMethod · 0.80
split_progressMethod · 0.80
loadFunction · 0.50
PathClass · 0.50
create_databaseMethod · 0.45
save_auto_snapshotMethod · 0.45

Tested by 1

mainFunction · 0.64