PHPackages                             rithlock/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. rithlock/vich-uploader-serialization-bundle

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

rithlock/vich-uploader-serialization-bundle
===========================================

Provides integration between VichUploaderBundle and JMSSerializerBundle.

v3.1.2(4y ago)03.0kMITPHPPHP &gt;=7.3.0

Since Nov 29Pushed 4y agoCompare

[ Source](https://github.com/Rithlock/VichUploaderSerializationBundle)[ Packagist](https://packagist.org/packages/rithlock/vich-uploader-serialization-bundle)[ Docs](https://github.com/fre5h/VichUploaderSerializationBundle)[ GitHub Sponsors](https://github.com/fre5h)[ RSS](/packages/rithlock-vich-uploader-serialization-bundle/feed)WikiDiscussions v2.4.2-odmV3 Synced 4w ago

READMEChangelogDependencies (16)Versions (32)Used By (0)

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

[](#vichuploaderserializationbundle)

Provides integration between [VichUploaderBundle](https://github.com/dustin10/VichUploaderBundle "VichUploaderBundle") and [JMSSerializerBundle](https://github.com/dustin10/VichUploaderBundle "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/6bec3326186c60bbe9a772758252e94d95f3b5ca750ebc1c776a40bcdc067a58/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f66726535682f5669636855706c6f6164657253657269616c697a6174696f6e42756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/fre5h/VichUploaderSerializationBundle/)[![Build Status](https://camo.githubusercontent.com/f49d2fe8618aae11994bb417c2002b1d8d6f7d56e5330a79d8f14dd187ca2b30/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f66726535682f5669636855706c6f6164657253657269616c697a6174696f6e42756e646c652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/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)[![StyleCI](https://camo.githubusercontent.com/79e9a3538cdeac008575f7fa35c3a59465be4d563c6cda0a5af5b3abe97482f3/68747470733a2f2f7374796c6563692e696f2f7265706f732f34373033373735312f736869656c643f7374796c653d666c61742d737175617265)](https://styleci.io/repos/47037751)[![Gitter](https://camo.githubusercontent.com/38615bd37fa667fefc3415d970da6c8f0de8796527cb97a89dfc59435f3189bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769747465722d6a6f696e253230636861742d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://gitter.im/fre5h/VichUploaderSerializationBundle)

[![SensioLabsInsight](https://camo.githubusercontent.com/e7ff99e9d7cb626107bac3b199c39f877a07ba583cffa4fb76f006ae2987cd42/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f61343065316163362d336232622d343430352d623763352d3533643032306135636639332f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/a40e1ac6-3b2b-4405-b7c5-53d020a5cf93)[![knpbundles.com](https://camo.githubusercontent.com/a1f85caf8d4e3ae2db95ac8ec4c6bcd53637c51ea47d2b7272848d0efe37d012/687474703a2f2f6b6e7062756e646c65732e636f6d2f66726535682f5669636855706c6f6164657253657269616c697a6174696f6e42756e646c652f62616467652d73686f7274)](http://knpbundles.com/fre5h/VichUploaderSerializationBundle)

Requirements
------------

[](#requirements)

- PHP 7.1 and *later*
- Symfony 3.4, 4.3 and *later*

Installation
------------

[](#installation)

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

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)

```
