- What is 1tomany/data-uri used for in Laravel?
- 1tomany/data-uri converts RFC2397 data URIs, base64 strings, local filesystem paths, and public HTTP/HTTPS URLs into immutable TemporaryFile value objects. It is useful in Laravel for upload processing, API payloads, and background jobs where you need a temporary file with an inferred MIME type and optional filename. By default the temporary file cleans up its filesystem resources when destroyed or garbage collected.
- How do I install 1tomany/data-uri?
- Install it with composer require 1tomany/data-uri. The package requires PHP 8.1+ and is compatible with Laravel 10+, with only symfony/filesystem as a core dependency. After v7.0.3 the Symfony bundle ships from the same repository, so check that bundle-only requirements such as symfony/http-kernel are not pulled into your app's require block.
- Does 1tomany/data-uri support Laravel 10 and PHP 8.1?
- Yes. The package is compatible with PHP 8.1+ and Laravel 10+, and its lightweight dependency on symfony/filesystem reduces conflict risk with Laravel's ecosystem. It has no Laravel service provider or facade, so you use the DataDecoder class directly or wrap it in your own adapter.
- How do I decode a base64 string to a temporary file?
- Use DataDecoder::decodeBase64() when the input is known to be base64 encoded but is not an RFC2397 data URI. Pass the base64 string, the MIME type, and an optional filename; it returns a TemporaryFile implementing TemporaryFileInterface. The type argument is required for this helper, so specify it explicitly.
- Can 1tomany/data-uri decode data URIs, local files, and remote URLs?
- Use DataDecoder::decode() for RFC2397 data URIs, accessible filesystem paths, and public HTTP/HTTPS URLs. Under the hood it uses fopen() and stream_get_contents(), so any stream wrapper PHP supports can work. The method returns a TemporaryFile value object with detected or supplied metadata.
- How do I preserve the original filename and set the MIME type?
- Yes. decode() accepts a type argument for the MIME type and a name argument for the temporary filename, which is useful for preserving original upload names. If type is omitted, the package detects it from the file extension or mime_content_type(). For ambiguous files such as Markdown, pass an explicit type like text/markdown because auto-detection may return text/plain.
- When are temporary files deleted?
- By default a TemporaryFile deletes the filesystem resources it knows about when it is explicitly destructed or garbage collected. The assessment notes this auto-deletion is not configurable and there is no manual delete() hook on the interface. In long-running processes such as queue workers, review object lifetimes to avoid premature cleanup or unexpected file removal.
- Is 1tomany/data-uri suitable for large files?
- The decoder streams with fopen() and stream_get_contents(), which supports low-memory processing of large files such as videos and PDFs. Practical limits still come from PHP settings like memory_limit and upload_max_filesize. Test with your expected payload sizes and storage streams.
- Does 1tomany/data-uri integrate with Laravel Storage?
- There is no native Laravel FilesystemAdapter, service provider, or facade, so integrating with Storage::put() requires a lightweight adapter or manual wrapping. The v7.0.3 merge of the Symfony bundle into the main repository is a packaging change and does not close that Laravel integration gap. The package complements Laravel's filesystem contracts but is not a drop-in Storage driver.
- Is it safe to decode untrusted URLs with 1tomany/data-uri?
- The package does not include validation middleware or built-in checks for malicious URIs, SSRF, or oversized payloads when decoding HTTP/HTTPS URLs. Add your own validation layer, such as URL allowlists or Guzzle-based checks, before passing untrusted input to decode(). Also prefer explicit MIME types when accuracy matters.