# Download attachment

## downloadAttachment()

Gets executed when a customer downloads a ticket attachment.

### Parameters

<table><thead><tr><th width="142">Type</th><th width="166">Name</th><th>Description</th></tr></thead><tbody><tr><td>Ticket</td><td>$ticket</td><td>The Ticket object of hostware. The $ticket->ticket_provider_external_id contains the external ticket id.</td></tr><tr><td>TicketAttachment</td><td>$ticketAttachment</td><td>TicketAttachment model containing the ID.</td></tr></tbody></table>

### Response

Download of the file

### Example Code

```php
public function downloadAttachment(Ticket $ticket, TicketAttachment $attachment): BinaryFileResponse {
    $ticketMessages = $this->getTicketMessages($ticket->ticket_provider_external_id);
    
    /** @var TicketMessageAttachmentResponse $attachmentDetails */
    $attachmentDetails = $ticketMessages->pluck('attachments')->flatten()->where('id', $attachment->file_path)->first();
    
    $tempImage = tempnam(sys_get_temp_dir(), $attachment->name);
    copy($attachmentDetails->url, $tempImage);
    
    return response()->download($tempImage, $attachment->name);
}
```

### Testing

You can test this function by downloading a ticket attachment as a customer.
