Use case: Update an attachment of an annotation
Before you start
Before you update an attachment of an annotation, ensure you have completed the following prerequisites:
- Verify Permissions: Confirm that you have the necessary rights to modify the attachment. Typically, you'll need to be the original creator of the attachment, the annotation owner, or have appropriate administrative permissions.
- Identify the Attachment: Locate the specific attachment you want to update. You'll need its unique identifier to perform this action.
- Prepare Updated Content: If updating the file content, ensure the new file is ready and meets any system requirements (size limits, file format, etc.).
- Set Up SDK Environment: Ensure your Unity environment is properly configured with the Collaboration SDK to interact with the annotation system.
How do I...?
Update an attachment
To modify the name, description, or other metadata of an existing attachment:
- Identify the Project Identifier: Ensure you have the correct project identifier (GUID) for the project.
- Identify the Annotation: Determine which annotation should receive the attachment.
- Identify the Attachment: Determine which attachment should receive the update.
- Prepare the Update Request: Create an
UpdateFileAttachmentRequestor anUpdateSpatial3DAttachmentRequestobject with the new metadata values. - Use the SDK: Call the
UpdateAnnotationAttachmentAsyncmethod in the Unity Collaboration SDK with the required properties. - Handle Responses: Ensure your implementation verifies whether the update was successful and handles any errors appropriately.
Example:
var projectId = ProjectController.SelectedProjectId.Value;
var annotationId = new AnnotationId();
var attachmentId = new AttachmentId();
var updateAttachmentRequest = new UpdateFileAttachmentRequest(
filePath: "path/to/attachment.txt",
fileSize: 12345,
fileType: "text/plain",
contentType: "text/plain");
// - or -
var updateAttachmentRequest = new UpdateSpatial3DAttachmentRequest(
label: "updated-text-for-the-label", // Replace with updated text
position: new SpatialPosition(), // Replace with updated spatial attachment position
camera: new CameraDetails(), // Replace with updated camera data structure
time: new TimeDetails(), // Replace with actual time data structure
local: new LocalSpaceDetails(), // Replace with actual local space details. Contains data for the attachment with spatial parameters that are relative to parent
);
// - or -
var updateAttachmentRequest = new UpdateSketchAttachmentRequest(
sketchData: "{ "dataProperty" : "data" }", // Replace with updated sketch data
camera: new CameraDetails(), // Replace with updated camera data structure
);
await annotationManagement.UpdateAnnotationAttachmentAsync(
projectId: projectId,
annotationId: annotationId,
attachmentId: attachmentId,
updateAttachmentRequest,
cancellationToken: token
);
For more information on working with attachments, see the documentation on creating attachments and deleting attachments.