File
synapseclient.entity.File
¶
Bases: Entity
, Versionable
Represents a file in Synapse.
When a File object is stored, the associated local file or its URL will be stored in Synapse.
A File must have a path (or URL) and a parent. By default, the name of the file in Synapse
matches the filename, but by specifying the name
attribute, the File Entity name can be different.
Changing File Names¶
A Synapse File Entity has a name separate from the name of the actual file it represents. When a file is uploaded to Synapse, its filename is fixed, even though the name of the entity can be changed at any time. Synapse provides a way to change this filename and the content-type of the file for future downloads by creating a new version of the file with a modified copy of itself. This can be done with the synapseutils.copy_functions.changeFileMetaData function.
import synapseutils
e = syn.get(synid)
print(os.path.basename(e.path)) ## prints, e.g., "my_file.txt"
e = synapseutils.changeFileMetaData(syn, e, "my_newname_file.txt")
Setting fileNameOverride will not change the name of a copy of the file that's already downloaded into your local cache. Either rename the local copy manually or remove it from the cache and re-download.:
syn.cache.remove(e.dataFileHandleId)
e = syn.get(e)
print(os.path.basename(e.path)) ## prints "my_newname_file.txt"
PARAMETER | DESCRIPTION |
---|---|
path |
Location to be represented by this File
DEFAULT:
|
name |
Name of the file in Synapse, not to be confused with the name within the path
|
parent |
Project or Folder where this File is stored
DEFAULT:
|
synapseStore |
Whether the File should be uploaded or if only the path should be stored when synapseclient.Synapse.store is called on the File object.
DEFAULT:
|
contentType |
Manually specify Content-type header, for example "application/png" or "application/json; charset=UTF-8"
|
dataFileHandleId |
Defining an existing dataFileHandleId will use the existing dataFileHandleId The creator of the file must also be the owner of the dataFileHandleId to have permission to store the file.
|
properties |
A map of Synapse properties
DEFAULT:
|
annotations |
A map of user defined annotations
DEFAULT:
|
local_state |
Internal use only
DEFAULT:
|
Creating instances
Creating and storing a File
# The Entity name is derived from the path and is 'data.xyz'
data = File('/path/to/file/data.xyz', parent=folder)
data = syn.store(data)
Setting the name of the file in Synapse to 'my entity'
# The Entity name is specified as 'my entity'
data = File('/path/to/file/data.xyz', name="my entity", parent=folder)
data = syn.store(data)
Source code in synapseclient/entity.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
|