Storing attachments | laravel-webhook-client-go | Spatie       

 SPATIE  

laravel-webhook-client-go
=========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-client-go](https://spatie.be/docs/laravel-webhook-client-go/v1)  Storing attachments

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-webhook-client-go/v1) 

  Storing attachments    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-client-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-client-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-webhook-client-go/v1/usage)
- [ Customizing the package ](https://spatie.be/docs/laravel-webhook-client-go/v1/customizing-the-package)
- [ Storing attachments ](https://spatie.be/docs/laravel-webhook-client-go/v1/attachments)
- [ Testing ](https://spatie.be/docs/laravel-webhook-client-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-webhook-client-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-client-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-webhook-client-go/v1/support-us)

 Storing attachments
===================

By default, the package collects native Laravel uploads, including nested and repeated file fields. Files are stored in the dedicated attachments column, separate from the payload. A text or JSON input field called `attachments` is never overwritten.

Each `Attachment` holds the original filename, detected MIME type, size, upload error code, original temporary path and content. Content uses `[]byte`, which JSON stores as base64. The temporary path is metadata only and is not usable after the request finishes.

```
files, err := call.GetAttachments()
if err != nil {
    return err
}
for _, file := range files {
    reader := file.Open()
    // Copy reader to your chosen destination.
    _ = reader
}
```

`Open` reads persisted bytes without creating a temporary file. Treat filenames as untrusted metadata, never filesystem paths. `GetAttachments` reads the dedicated column first, including an explicitly empty list. If that column is nil, it can decode PHP-style legacy `payload["attachments"]` metadata. Malformed legacy data returns an error. This is an import convenience, not automatic PHP database schema migration.

Set `cfg.StoreAttachments = false` to skip file-content extraction entirely. Set `cfg.Attachments` to your own extraction function to choose specific files or add validation. The default `AttachmentsFromRequest` uses native map binding to enumerate uploads. `AttachmentFromUpload` converts one `*web.Upload` directly.

Laravel consumes multipart bodies before handlers run. The default body-HMAC validator rejects multipart requests with `ErrBodyUnavailable`. Configure a sender-specific validator for its documented multipart authentication, such as a signed metadata header. Do not silently authenticate an empty body.

Keep Laravel's request, field and upload limits enabled. Base64 adds about a third to the stored file size. Apply endpoint-appropriate upload limits and retain only the files you need.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
