update_resource Method
Updates the currently selected resource.
Syntax
def update_resource() -> None: ...
Remarks
This method updates the metadata for the file or folder resource currently selected by remote_id or remote_path. For file resources, the file data can optionally be updated as well.
Usage
There must be an item in the Resource* properties whose resource_id or resource_path property matches remote_id or remote_path before this method is called.- If necessary, call get_resource_info or list_resources to ensure an item with the resource's latest information is present in the Resource* properties.
- Modify the item's Resource* properties as desired; the following properties are supported:
- resource_description (only updated if not empty; only applicable for OneDrive Personal)
- resource_name
- resource_parent_id (only updated if not empty)
- resource_parent_path (only updated if not empty and resource_parent_id is empty)
- For file resources, you may set local_file or resource_data if you wish to update the file data on the server. (Refer to upload_file for more information about simple vs. resumable uploads and encrypting the file data before uploading.)
- Finally, call this method to update the resource.
// Load the latest information about the resource into the Resources collection. onedrive.RemotePath = "/folder/CoolStuff1.txt"; onedrive.GetResourceInfo(); // We'll update the file resource's name, description, and content. onedrive.ResourceData = "new file content"; onedrive.Resources[0].Name = "CoolStuff2.txt"; onedrive.Resources[0].Description = "This is a text file with cool stuff in it"; onedrive.UpdateResource();
Name Conflict Resolution
When updating a resource's name and/or parent, keep in mind that the server's name conflict resolution behavior will follow these steps:- If the RenameIfExists configuration setting is enabled, the server will modify the new name of the resource to be unique, if necessary. Refer to the RenameIfExists configuration setting for more information.
- Otherwise, if the overwrite property is enabled, the server will replace the existing (other) resource with the one being updated.
- Otherwise, the server will return an error.