import Foundation public struct MessageAttachment: Codable, Sendable, Equatable, Identifiable { public let id: String public let revision: Int64 public let kind: String public let name: String public let mediaType: String public let size: Int64 public let sha256: String public let width: Int public let height: Int public let messageId: String public let createdAt: Date } extension EquipoClient { public func upload(_ file: AttachmentFile, progress: @escaping @Sendable (Double) -> Void) async throws -> MessageAttachment { var request = APIRequest("POST", "/attachments", body: file.data, bearer: token) request.contentType = file.mediaType let escaped = file.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? "file" request.contentDisposition = "attachment; filename*=UTF-8''" + escaped request.uploadProgress = UploadProgress(progress) return try await send(request) } public func attachmentData(_ id: String, preview: Bool = false) async throws -> Data { let id = id.addingPercentEncoding(withAllowedCharacters: .alphanumerics.union(CharacterSet(charactersIn: "_-"))) ?? "" var request = APIRequest("GET", "/attachments/\(id)" + (preview ? "/preview" : ""), bearer: token) request.maximumResponseBytes = AttachmentLimits.maxBytes let response = try await transport.send(request) guard (200..<300).contains(response.status) else { throw Self.error(response) } guard response.data.count <= AttachmentLimits.maxBytes else { throw EquipoAPIError.tooLarge } return response.data } }