All Projects → goetas → MultipartUploadBundle

goetas / MultipartUploadBundle

Licence: MIT license
Symfony multipart/related/mixed/alternative content type handler (rfc1341).

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to MultipartUploadBundle

symfony-rest-api-bundle
Integrates the MediaMonks REST API Spec in Symfony
Stars: ✭ 17 (-19.05%)
Mutual labels:  symfony-bundle
SlackBundle
SlackBundle for Symfony2 with Guzzle-Integration
Stars: ✭ 39 (+85.71%)
Mutual labels:  symfony-bundle
LiipImagineSerializationBundle
Provides integration between LiipImagineBundle and JMSSerializerBundle
Stars: ✭ 24 (+14.29%)
Mutual labels:  symfony-bundle
gulp-rev-versions-bundle
A bundle that allows symfony to get the version of assets versioned with gulp-rev
Stars: ✭ 13 (-38.1%)
Mutual labels:  symfony-bundle
SensioBuzzBundle
No description or website provided.
Stars: ✭ 89 (+323.81%)
Mutual labels:  symfony-bundle
SonataDashboardBundle
[Abandoned] Provides a Dashboard management through container and block services
Stars: ✭ 17 (-19.05%)
Mutual labels:  symfony-bundle
Csaguzzlebundle
A bundle integrating Guzzle >=4.0 in Symfony
Stars: ✭ 248 (+1080.95%)
Mutual labels:  symfony-bundle
hashed-asset-bundle
Apply an asset version based on a hash of the asset for symfony/asset
Stars: ✭ 24 (+14.29%)
Mutual labels:  symfony-bundle
LiipSearchBundle
[DEPRECATED] Google XML API for searching is discontinued
Stars: ✭ 35 (+66.67%)
Mutual labels:  symfony-bundle
PRRecaptchaBundle
Recaptcha v3 bundle for Symfony
Stars: ✭ 14 (-33.33%)
Mutual labels:  symfony-bundle
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (+14.29%)
Mutual labels:  symfony-bundle
vuejs-uploader
Vue multipart file uploader
Stars: ✭ 62 (+195.24%)
Mutual labels:  multipart-uploads
stampie-bundle
stampie.github.io/
Stars: ✭ 26 (+23.81%)
Mutual labels:  symfony-bundle
sonata-multiupload-bundle
No description or website provided.
Stars: ✭ 29 (+38.1%)
Mutual labels:  symfony-bundle
jsonrpc-bundle
JSON-RPC server for Symfony: exposes services registered in the service container as JSON-RPC-webservices
Stars: ✭ 31 (+47.62%)
Mutual labels:  symfony-bundle
Lexikmaintenancebundle
This Symfony2 bundle allows you to place your website in maintenance mode by calling two commands in your console. A page with status code 503 appears to users, it is possible to authorize certain ips addresses stored in your configuration.
Stars: ✭ 253 (+1104.76%)
Mutual labels:  symfony-bundle
apisearch-bundle
⛵ Apisearch Symfony-Drift Bundle
Stars: ✭ 23 (+9.52%)
Mutual labels:  symfony-bundle
hashids-bundle
Integrates hashids/hashids in a Symfony project
Stars: ✭ 43 (+104.76%)
Mutual labels:  symfony-bundle
EasyAdminPlusBundle
EasyAdminPlusBundle is a Symfony 4 wrapper for the amazing EasyCorp/EasyAdminBundle
Stars: ✭ 39 (+85.71%)
Mutual labels:  symfony-bundle
SonataDoctrineMongoDBAdminBundle
Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
Stars: ✭ 64 (+204.76%)
Mutual labels:  symfony-bundle

GoetasMultipartUploadBundle

Build Status Latest Stable Version Code Coverage Scrutinizer Code Quality

Symfony multipart/related, multipart/alternative and multipart/mixed content type handler.

This bundle implements a subset of the https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html specifications and allows you to deal with Content-Type: multipart/*; requests with Symfony.

Install

Run composer require goetas/multipart-upload-bundle

Add bundle to symfony (if not using symfony/flex)

Request format

A multipart/related request could look like this:

Host: localhost
Content-Type: multipart/related; boundary=19D523FB

--19D523FB
Content-Type: application/json

{
    "content": "Some JSON content"
}
--19D523FB
Content-Type: image/png
Content-Disposition: form-data; name="image"; filename="image.jpg"
Content-MD5: 314ca078416a9b27efbe338ac5a2f727

... binary content...
Content-Type: text/html
Content-Disposition: form-data; name="content"
Content-MD5: 314ca078416a9b27efbe338ac5a2f727

<a href="https://github.com/goetas/MultipartUploadBundle">HTML content</a>

--19D523FB
Content-Type: image/png
Content-Disposition: attachment; filename="image.jpg"
Content-MD5: 314ca078416a9b27efbe338ac5a2f727

... binary content...

--19D523FB
Content-Type: octet/stream
X-Custom-Header: header value

... binary content...

--19D523FB--

Usage

Controller

Body will not be decoded automatically, you can decode it by yourself or use FOSRestBundle to handle it transparently

public function indexAction(Request $request)
{
    if ('application/json' == $request->headers->get('content-type')) {
        $data = json_decode($request->getContent(), true);
    }
}

Form Fields

Parts with form-data; name= in Content-Disposition part's headers will be treated like an regular uploaded file.

$html = $request->request->get('content');

Can be used with Symfony's form builder

$builder->add('content', TextAreaType::class);

Uploaded Files

Parts with form-data; name= and filename= in Content-Disposition part's headers will be treated like an regular uploaded file.

$file = $request->files->get('image');

Can be used with Symfony's form builder

$builder->add('image', FileType::class);

Attachment Files

Parts with attachment; filename= in Content-Disposition part's headers will be treated as an attachment file.

$attachment = $request->attributes->get('attachments')[0];

Related Parts

Parts without a filename will be treated as Riverline\MultiPartParser\StreamedPart object. Will be possible to access as well all the parts trough the related-parts attribute.

$part = $request->attributes->get('related-parts')[0];
  • Get part's headers
$headers = $part->getHeaders()->all();
  • Get part's content
$content = $part->getContent();
  • Get part's content as resource
$content = stream_get_contents($part->getContent(true));
  • First part injected

By default, when a message is multipart/*, the first part will become the Symfony message content. You can disable this by setting first_part_as_default to false.

$content = $request->getContent(); // content of the first part, not the whole message

Configurations

goetas_multipart_upload:
  first_part_as_default: true

Note

The code in this project is provided under the MIT license. For professional support contact [email protected] or visit https://www.goetas.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].