{"id":15365951,"url":"https://github.com/andywer/larablob","last_synced_at":"2025-04-23T19:20:16.662Z","repository":{"id":28006883,"uuid":"31501372","full_name":"andywer/larablob","owner":"andywer","description":"Local blob store for the famous Laravel PHP web framework.","archived":false,"fork":false,"pushed_at":"2015-08-27T19:19:43.000Z","size":264,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T16:55:53.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andywer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-01T15:55:33.000Z","updated_at":"2015-03-18T07:36:31.000Z","dependencies_parsed_at":"2022-08-21T03:10:12.795Z","dependency_job_id":null,"html_url":"https://github.com/andywer/larablob","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Flarablob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Flarablob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Flarablob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Flarablob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andywer","download_url":"https://codeload.github.com/andywer/larablob/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250497022,"owners_count":21440244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T13:16:47.364Z","updated_at":"2025-04-23T19:20:16.645Z","avatar_url":"https://github.com/andywer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Larablob - Laravel blob store\n[![Build Status](https://travis-ci.org/andywer/larablob.svg?branch=master)](https://travis-ci.org/andywer/larablob)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/andywer/larablob/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/andywer/larablob/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/andywer/larablob/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/andywer/larablob/?branch=master)\n\nFile uploads made easy! PHP blob store for the famous [Laravel](http://laravel.com/) web framework.\n\n\n## Features\n\n- File system based blob storage\n- Blobs grouped by named blob groups\n- Supports storing blob metadata (stored as JSON files)\n- Compatible with Laravel 4.1, 4.2 \u0026 5.0\n\n\n## Why use it?\n\n- You will frequently need to store binary large objects (blobs) like user-uploaded images\n- Larablob stores the data separate from your database\n- So your database dumps stay small\n- Backups are dead easy: Just copy the blob store directory\n- Easy to set up and simple to use\n- Frequent security pitfalls have been considered and cared for\n- Clean high-level API and uncomplicated access on filesystem layer\n\n\n## How To\n\n```php\n\u003c?php\nuse Larablob\\Facades\\BlobStore;\n\n$blobGroup = BlobStore::getBlobGroup('profile-pics', true);     // true indicates to create the group if it's not yet present\n\n$blob = $blobGroup-\u003ecreateBlob();\n$blob-\u003eimportFromFile('php://input');\n\necho \"Saved request body to filesystem without worrying about malicious user-given file names!\\n\";\necho \"And we now have a high-level API for using it, too.\";\n\n$blob-\u003esave(\"Hello world!\");\necho \"Stored new data in blob: \".$blob-\u003edata().\"\\n\";\n\necho \"All profile-pic blobs:\\n\";\nforeach ($blobGroup-\u003eallBlobs() as $blob) {\n    echo \"-\u003e \".$blob-\u003egetId().\" (size: \".$blob-\u003esize().\")\\n\";\n}\n\necho \"Cleaning up...\\n\";\n$blobGroup-\u003edelete();\n```\n\n\n## Installation\n\nJust run the following command in your project directory:\n\n```bash\ncomposer require andywer/larablob=dev-master      # dev-laravel4 for Laravel 4.1 or 4.2\n```\n\nNow add the following line to the `providers` array of your `config/app.php` file:\n\n```php\n    'providers' =\u003e [\n        /* ... */\n        'Larablob\\LarablobServiceProvider'\n    ]\n```\n\nAnd optionally:\n\n```php\n    `aliases` =\u003e [\n        /* ... */\n        'BlobStore' =\u003e 'Larablob\\Facades\\BlobStore'\n    ]\n```\n\n\n## Laravel 4\n\nIf you still use Laravel 4.1 or 4.2, install the package like:\n\n```bash\ncomposer require andywer/larablob=dev-laravel4\n```\n\n\n## Example\n\nUsage is simple and straight forward. The following sample code shows how to easily store random HTTP POST data and\nrelated metadata into a blob store.\n\n```php\n\u003c?php\nnamespace app\\Http\\Controllers;\n\nuse Larablob\\Facades\\BlobStore;\nuse Request;\n\nclass PostController extends Controller {\n\n    /** @var \\Larablob\\Storage\\BlobGroup */\n    protected $blobGroup;\n\n\n    public function __construct()\n    {\n        // the `true` indicates that a new group shall be created if it does not exist\n        $this-\u003eblobGroup = BlobStore::getBlobGroup('post-data', true);\n    }\n\n    /**\n     * GET parameters: ['id', 'mime-type']\n     * POST data: Random data\n     */\n    public function postDataUpload()\n    {\n        $blob = $this-\u003eblobGroup-\u003ecreateBlob(Request::input('id'));\n        // if we would not pass a blob ID here, the blob store would generate a random UUID v4 for us\n\n        $blob-\u003eimportFromFile('php://input');\n        $blob-\u003esetMeta([ 'type' =\u003e Request::input('mime-type') ]);\n\n        return response()-\u003ejson([ 'storedBytes' =\u003e $blob-\u003esize() ]);\n    }\n\n    /**\n     * GET parameters: ['id']\n     */\n    public function retrieveData()\n    {\n        $blob = $this-\u003eblobGroup-\u003egetBlob(Request::input('id'));\n\n        return response()-\u003edownload($blob-\u003egetFilePath());\n    }\n\n    /**\n     * GET parameters: ['id']\n     */\n    public function retrieveMetadata()\n    {\n        $blob = $this-\u003eblobGroup-\u003egetBlob(Request::input('id'));\n        $meta = $blob-\u003egetMeta();\n\n        return response()-\u003ejson([ 'type' =\u003e $meta-\u003etype, 'size' =\u003e $blob-\u003esize() ]);\n    }\n\n    /**\n     * Parameters: None\n     */\n    public function listAll()\n    {\n        return response()-\u003ejson([\n            'IDs' =\u003e $this-\u003eblobGroup-\u003eallBlobIds()\n        ]);\n    }\n\n    /**\n     * GET parameters: ['id']\n     */\n    public function removeData()\n    {\n        $this-\u003eblobGroup-\u003egetBlob(Request::input('id'))-\u003edelete();\n        // getBlob() throws a \\Larablob\\Exceptions\\NotFoundException if a bad ID is passed\n\n        return response()-\u003ejson([ 'success' =\u003e true ]);\n    }\n\n}\n```\n\n\n## API\n\n### Larablob\\Facades\\BlobStore\n\n##### BlobStore::getPath()\nReturns the path to the blob store base directory on the file system. Defaults to `{project-dir}/storage/larablob`\n\n##### BlobStore::createBlobGroup(string $name)\nCreates a new blob group using the supplied `$name` and returns the `BlobGroup` instance. May throw a `Larablob\\Exceptions\\NamingException` or a `Larablob\\Exceptions\\AlreadyPresentException`.\n\n##### BlobStore::getBlobGroup(string $name, bool $autoCreate = false)\nReturns a `BlobGroup` instance which you can use to create, read, update or delete blobs. If the blob group cannot be found a `Larablob\\Exceptions\\NotFoundException` is thrown, unless `$autoCreate` is set to true (in this case a new blob group with the given name will be created and returned).\n\n##### BlobStore::allBlobGroups()\nReturns an array containing all existing `BlobGroup`s.\n\n##### BlobStore::allBlobGroupNames()\nReturns an array containing all existing blob group's names.\n\n##### BlobStore::blobGroupExists(string $name)\nReturns `true` if a blob group with this name exists, `false` if not.\n\n\n### Larablob\\Storage\\BlobGroup\n\n##### $blobGroup-\u003egetName()\nReturns the name of the blob group.\n\n##### $blobGroup-\u003egetStore()\nReturns the `Larablob\\Storage\\BlobStore` instance of the blob group's store.\n\n##### $blobGroup-\u003ecreateBlob(string $id = null)\nCreates a new blob in the blob group and returns a `Blob` instance. You can optionally pass an `$id` to the method (any non-empty string will do; the filename will be `urlencode($id)`) or otherwise Larablob will create a random `UUID v4` for the blob.\n\nHint: A blob's ID must only be unique in the context of it's blob group.\n\n##### $blobGroup-\u003egetBlob(string $id, bool $autoCreate = false)\nReturns a `Blob` instance. If the blob cannot be found a `Larablob\\Exceptions\\NotFoundException` is thrown, unless `$autoCreate` is set to true (in this case a new blob with the given id will be created and returned).\n\n##### $blobGroup-\u003eallBlobs()\nReturns an array containing all `Blob`s of this blob group.\n\n##### $blobGroup-\u003eallBlobIds()\nReturns an array containing all blob's identifiers (in this blob group).\n\n##### $blobGroup-\u003eblobExists(string $id)\nReturns `true` if a blob with the given ID exists, `false` if not.\n\n##### $blobGroup-\u003edelete()\nDeletes the blob group and all its blobs. Attention: Trying to access the blob group or it's contents after calling `delete()` may result in an exception being thrown.\n\n\n### Larablob\\Storage\\Blob\n\n#### $blob-\u003egetId()\nReturns the blob's identifier as a `string`.\n\n#### $blob-\u003egetFilePath()\nReturns the path to the blob file as a `string`.\n\n#### $blob-\u003egetBlobGroup()\nReturns the `BlobGroup` instance of the blob group that contains this blob.\n\n#### $blob-\u003edata()\nReturns the blob's data as a `string`.\n\n#### $blob-\u003esize()\nReturns an `integer` indicating the blob data's size in bytes.\n\n#### $blob-\u003esave(string $data)\nUpdate the blob's data. Overwrites existing data.\n\n#### $blob-\u003eimportFromFile(string $filePath)\nA shortcut to saving the contents of the given file to the blob. Throws a `Larablob\\Exceptions\\FileSystemException` if the file cannot be read.\n\n#### $blob-\u003egetMeta()\nReturns the blob's metadata previously set by `setMeta()` as a generic object (`stdClass`).\n\n#### $blob-\u003esetMeta(mixed $metadata)\nSaves custom metadata for the blob. The metadata will be encoded to a JSON string and saved to another file.\n\n#### $blob-\u003edelete()\nDeletes the blob and it's metadata. Attention: Trying to access the blob or it's content after calling `delete()` may result in an exception being thrown.\n\n\n## Configuration\n\nCurrently the only thing to configure is the store path. It defaults to a directory `larablob` in the application's\nstorage directory.\n\n\n## License\nThis software is licensed under the terms of the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandywer%2Flarablob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandywer%2Flarablob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandywer%2Flarablob/lists"}