1tomany/data-uri
Parse data URIs, base64 strings, plain text, URLs, or local files into a temporary file via an immutable value object. Auto-detect or override MIME type, set an optional display name, and the temp file is deleted automatically on destruct.
Storage facade and Filesystem contracts but requires lightweight adaptation (e.g., wrapping DataUriInterface in a custom adapter).DataDecoder::decode() method’s versatility reduces the need for multiple libraries.stream_get_contents(), enabling low-memory processing of large files (e.g., videos, PDFs) without loading entire contents into RAM.symfony/filesystem (v7.2/8.0), reducing conflict risks with Laravel’s ecosystem. Compatible with PHP 8.1+ and Laravel 10+.Filesystem adapters (e.g., s3, local).mime_content_type(), useful for preserving metadata (e.g., text/markdown). The type parameter in decode() allows overriding defaults.name parameter ensures original filenames are retained (critical for user uploads or debugging), addressing a common pain point in Laravel file handling.FilesystemAdapter: Requires manual wrapping to integrate with Laravel’s Storage facade (e.g., Storage::put()).Guzzle for HTTP validation).delete() method on DataUriInterface).memory_limit or upload_max_filesize may constrain processing..md as text/plain). Explicit types are recommended for reliability.FilesystemAdapter to enable seamless use with Storage::put()/Storage::disk()?Storage::put('temp-file', (new DataUriAdapter($decoder))->read($dataUri));InvalidDataUriException).Validator or middleware (e.g., reject non-HTTPS URLs).fread() loops)?symfony/mime worth adding for more robust MIME type detection?delete() method) for edge cases?Filesystem tests for compatibility?DataUriInterface can be adapted to Laravel’s Filesystem contracts (e.g., Streamable, Readable) via a custom adapter. This enables use with Storage::put(), Storage::disk(), and background jobs.Http client (e.g., Http::get()) or Guzzle for remote URL handling.Validator or form request validation to sanitize data URIs before processing.symfony/filesystem (v7.2/8.0), which aligns with Laravel’s Symfony components. No conflicts expected.DataUriInterface ensures thread safety.DataDecoder::decode().data:image/png;base64,...).https://example.com/file.pdf).storage/uploads/file.jpg).$name parameter).DataUriFilesystemAdapter implementing Laravel’s Filesystem contracts:
class DataUriAdapter implements Filesystem
{
public function read($path): string { ... }
public function write($path, $contents, $options = []): void { ... }
// ... other contract methods
}
Storage facade:
Storage::extend('data_uri', function () {
return new DataUriAdapter(new DataDecoder());
});
data_uri rule in Laravel’s Validator).DataUriInterface in queued jobs (e.g., ConvertUploadToPermanentStorageJob).symfony/filesystem (v7.2/8.0): Already used by Laravel.symfony/mime for enhanced MIME detection (not required).sys_get_temp_dir()).DataDecoder::decode() for broad use cases (data URIs, URLs, files).decodeBase64(), decodeText()) for performance-critical paths (e.g., API responses).Storage facade.symfony/filesystem) reduce maintenance burden.mimeType → format in v6.0.0).$name parameter) aids troubleshooting.How can I help you explore Laravel packages today?