PHPackages                             fresh/vich-uploader-serialization-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. fresh/vich-uploader-serialization-bundle

AbandonedArchivedSymfony-bundle[File &amp; Storage](/categories/file-storage)

fresh/vich-uploader-serialization-bundle
========================================

Provides integration between VichUploaderBundle and JMSSerializerBundle.

v3.3.0(3y ago)47197.8k↓23.7%12[1 issues](https://github.com/fre5h/VichUploaderSerializationBundle/issues)[1 PRs](https://github.com/fre5h/VichUploaderSerializationBundle/pulls)MITPHPPHP &gt;=7.3.0CI failing

Since Nov 29Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/fre5h/VichUploaderSerializationBundle)[ Packagist](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)[ Docs](https://github.com/fre5h/VichUploaderSerializationBundle)[ GitHub Sponsors](https://github.com/fre5h)[ RSS](/packages/fresh-vich-uploader-serialization-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (35)Used By (0)

VichUploaderSerializationBundle
===============================

[](#vichuploaderserializationbundle)

📦 Provides integration between [VichUploaderBundle](https://github.com/dustin10/VichUploaderBundle "VichUploaderBundle") and [JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle "JMSSerializerBundle"). Allows to generate full or relative URIs to entity fields mapped with `@Vich` and `@JMS` annotations during the serialization.

[![Scrutinizer Quality Score](https://camo.githubusercontent.com/0cf2b5d994e557881770f426e6284227d51636e70bdba7e5e34e07c073e9ed5b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f66726535682f5669636855706c6f6164657253657269616c697a6174696f6e42756e646c652f63692e79616d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/fre5h/VichUploaderSerializationBundle/)[![CodeCov](https://camo.githubusercontent.com/0b732f2ab5365eb3cc0e671bddf68a8f00d9b30d08bd809d0da0b3830e3acca9/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f66726535682f5669636855706c6f6164657253657269616c697a6174696f6e42756e646c652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/fre5h/VichUploaderSerializationBundle)[![License](https://camo.githubusercontent.com/3d54187b8dbfb901c857c2310ae994a87fc66b43a18e68fc0ae6286ae7aa4013/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f66726573682f766963682d75706c6f616465722d73657269616c697a6174696f6e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)[![Latest Stable Version](https://camo.githubusercontent.com/22376af6bd6a20008fd5122892c09d432f977ee5e5d72568d7e377861b43ece6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66726573682f766963682d75706c6f616465722d73657269616c697a6174696f6e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)[![Total Downloads](https://camo.githubusercontent.com/cfc0fe7b2ec4894a138b0ad0827d9edc10b52b9107f83d9c6ce7433e485de581/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66726573682f766963682d75706c6f616465722d73657269616c697a6174696f6e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fresh/vich-uploader-serialization-bundle)

Requirements 🧐
--------------

[](#requirements-)

- PHP 7.3, 7.4, 8.0, 8.1, 8.2
- Symfony 5.0, 5.1, 5.2, 5.3, 5.4, 6.0, 6.1, 6.2

Installation 🌱
--------------

[](#installation-)

`composer req fresh/vich-uploader-serialization-bundle='~3.3'`

Usage 🧑‍🎓
---------

[](#usage-‍)

Add the next class to the `use` section of your entity class.

```
use Fresh\VichUploaderSerializationBundle\Annotation as Fresh;
```

Bundle provides two annotations which allow the serialization of `@Vich\UploadableField` fields in your entities. At first you have to add `@Fresh\VichSerializableClass` to the entity class which has uploadable fields. Then you have to add `@Fresh\VichSerializableField` annotation to the uploadable field you want to serialize.

Annotation `@Fresh\VichSerializableClass` does not have any option.
Annotation `@Fresh\VichSerializableField` has one required option *value* (or *field*) which value should link to the field with `@Vich\UploadableField` annotation. It can be set like this `@Fresh\VichSerializableField("photoFile")` or `@Fresh\VichSerializableField(field="photoFile")`. Also there is another option `includeHost`, it is not required and by default is set to **true**. But if you need, you can exclude the host from the generated URI, just use the next variant of the annotation `@Fresh\VichSerializableField("photoFile", includeHost=false)`.

And also don't forget that to serialize Vich uploadable fields they also should be marked with `@JMS` annotations to be serialized.

The generated URI by default:

```
{
  "photo": "http://example.com/uploads/users/photos/5659828fa80a7.jpg",
  "cover": "http://example.com/uploads/users/covers/456428fa8g4a8.jpg",
}
```

The generated URI with `includeHost` set to `false`:

```
{
  "photo": "/uploads/users/photos/5659828fa80a7.jpg",
  "cover": "/uploads/users/covers/456428fa8g4a8.jpg",
}
```

### Example of entity with serialized uploadable fields

[](#example-of-entity-with-serialized-uploadable-fields)

```
