{"id":12469,"date":"2024-02-25T07:00:39","date_gmt":"2024-02-24T22:00:39","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=12469"},"modified":"2024-02-21T00:58:36","modified_gmt":"2024-02-20T15:58:36","slug":"magika-laravel-%e3%81%a7%e6%ad%a3%e7%a2%ba%e3%81%aa%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%bf%e3%82%a4%e3%83%97%e5%88%a4%e5%88%a5%e3%81%ae%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=12469","title":{"rendered":"Magika + Laravel \u3067\u6b63\u78ba\u306a\u30d5\u30a1\u30a4\u30eb\u30bf\u30a4\u30d7\u5224\u5225\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3044\u3064\u3082\u306f\u30a8\u30c3\u30af\u30b9\u304b\u3089\u65b0\u3057\u3044\u30c6\u30af\u30ce\u30ed\u30b8\u30fc\u306e\u60c5\u5831\u3092\u5f97\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3082\u3046\uff11\u3064\u79c1\u304c\u60c5\u5831\u6e90\u306b\u3057\u3066\u3044\u308b\u306e\u304c\u30cb\u30e5\u30fc\u30b9\u30a2\u30d7\u30ea\u3067\u3059\u3002<\/p>\n<p>\u904e\u53bb\u306e\u95b2\u89a7\u60c5\u5831\u304b\u3089\u300c<strong>\u3053\u308c\u3001\u3069\u3046\u305b\u597d\u304d\u3060\u308d\uff1f<\/strong>\u300d\u307f\u305f\u3044\u306a\u30cb\u30e5\u30fc\u30b9\u3092\u9078\u5225\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3068\u3066\u3082\u5feb\u9069\u306a\u3093\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u9593\u767a\u898b\u3057\u305f\u306e\u304c\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">Magika\uff08\u307e\u3058\u304b\uff09<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p><strong>\ud83d\udcdd \u53c2\u8003\u30da\u30fc\u30b8\uff1a<\/strong>\u00a0<a href=\"https:\/\/gigazine.net\/news\/20240216-google-magika-ai-file-type-identification\/\" target=\"_blank\" rel=\"noopener\">Google\u304cAI\u306e\u529b\u3067\u30d5\u30a1\u30a4\u30eb\u5f62\u5f0f\u3092\u6b63\u78ba\u306b\u8b58\u5225\u3059\u308b\u30c4\u30fc\u30eb\u300cMagika\u300d\u3092\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u3067\u516c\u958b<\/a><\/p>\n<p><code>Magika<\/code>\u306f\u30d5\u30a1\u30a4\u30eb\u306e\u5f62\u5f0f\uff08<code>mime-type<\/code>\u3068\u304b\uff09\u3092\u5224\u5225\u3057\u3066\u304f\u308c\u308b<code>Google<\/code>\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306a\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u3059\u308b\u3068\u3001\u3059\u3050\u3055\u307e\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n<p><strong style=\"font-size: 35px;\">Laravel \u306e\u901a\u5e38\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3088\u308a\u3082\u7cbe\u5ea6\u304c\u9ad8\u3044\u30d5\u30a1\u30a4\u30eb\u5224\u5225\u304c\u3067\u304d\u308b\u3058\u3083\u3093\uff01<\/strong><\/p>\n<p>\u3068\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f<code>Magika<\/code>\u306e\u30d5\u30a1\u30a4\u30eb\u5224\u5225\u3092<code>Laravel<\/code>\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4f55\u304b\u306e\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\u3002\ud83d\ude04\u2728<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9470 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png\" alt=\"\" width=\"294\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png 294w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13-276x300.png 276w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/>\u300c\u30b7\u30de\u30e4\u306e\u3046\u3069\u3093\u30b9\u30fc\u30d7<br \/>\n\u30b5\u30a4\u30b3\u30fc\uff01\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 10.x\u3001FastAPI 0.109.2<\/p>\n<h1>\u524d\u63d0\u3068\u3057\u3066<\/h1>\n<p>\u6b8b\u5ff5\u306a\u304c\u3089\u3001<code>Magika<\/code>\u306f <strong>2024.2.20<\/strong> \u73fe\u5728\u306e\u3068\u3053\u308d<code>Python<\/code>\u3068<code>JavaScript<\/code>\u306e\u307f\u3067\u52d5\u304f\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u4eca\u56de\u306f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u7c21\u5358\u306a<code>Python<\/code>\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001<code>PHP<\/code>\u306e\u4e2d\u304b\u3089<code>exec()<\/code>\u306a\u3069\u3092\u4f7f\u3063\u3066\u76f4\u63a5<code>Python<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u6a29\u9650\u3092\u3086\u308b\u3081\u305f\u308a\u3057\u3066\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u306b\u3042\u307e\u308a\u826f\u3044\u3068\u306f\u8a00\u3048\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u4eca\u56de\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u3067\u300c<strong>Laravel + Magika<\/strong>\u300d\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<ol>\n<li>Laravel \u306b\u30d5\u30a1\u30a4\u30eb\u9001\u4fe1<\/li>\n<li>FastAPI \u3067\u4f5c\u3063\u305f URL \u306b\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u9001\u4fe1<\/li>\n<li>Magika \u3067\u30d5\u30a1\u30a4\u30eb\u30bf\u30a4\u30d7\u3092\u30c1\u30a7\u30c3\u30af\u3057\u7d50\u679c\u3092\u8fd4\u3059<\/li>\n<li>\u8fd4\u3063\u3066\u304d\u305f\u60c5\u5831\u3092\u5143\u306b\u3057\u3066\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u300cOK or \u30c0\u30e1\u300d\u3092\u6c7a\u5b9a\u3059\u308b<\/li>\n<\/ol>\n<p>\u3064\u307e\u308a\u3001\u3061\u3087\u3063\u3068\u3057\u305f\u300c<strong>\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u5316<\/strong>\u300d\u3059\u308b\u308f\u3051\u3067\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u3001\u4eca\u56de\u3082\u697d\u3057\u3093\u3067\u3084\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u2757<\/p>\n<h1>Magika \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\uff08Python\uff09<\/h1>\n<p>\u3067\u306f\u3001\u307e\u305a\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067<code>Magika<\/code>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u8a66\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>pip install magika<\/strong><\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u7d42\u308f\u3063\u305f\u3089\u3001\u9069\u5f53\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u7528\u610f\u3057\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>magika test.jpg<\/strong><\/pre>\n<p>\u203b <code>test.jpg<\/code> \u306e\u90e8\u5206\u306f\u9069\u5b9c\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7d50\u679c\u3092\u51fa\u3057\u3066\u304f\u308c\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12471\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_1.png\" alt=\"\" width=\"315\" height=\"32\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_1.png 315w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_1-300x30.png 300w\" sizes=\"auto, (max-width: 315px) 100vw, 315px\" \/><\/p>\n<p>\u305f\u3060\u3057\u3001\u4eca\u56de\u306e\u30b1\u30fc\u30b9\u3060\u3068\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u306b\u304f\u3044\u306e\u3067\u3001<code>--json<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u3064\u3051\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>magika test.jpg --json<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u3053\u306e\u3088\u3046\u306b\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002\uff08\u4fbf\u5229\u3067\u3059\u306d\ud83d\udc4d\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12472\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_2.png\" alt=\"\" width=\"434\" height=\"553\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_2.png 434w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_2-235x300.png 235w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/p>\n<h1>FastAPI\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6b21\u306b<code>FastAPI<\/code>\uff08\u3068\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\uff09\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>pip install fastapi\r\npip install uvicorn<\/strong><\/pre>\n<p>\u203b\u306a\u304a\u3001\u79c1\u306e\u5834\u5408\u306f\u6700\u521d\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u8db3\u308a\u306a\u3044\u3068\u8a00\u308f\u308c\u3001\u4ee5\u4e0b\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002\u3082\u3057\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u5834\u5408\u306f\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>pip install python-multipart<\/strong><\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u9069\u5f53\u306a\u30d5\u30a9\u30eb\u30c0\u3092\u3064\u304f\u3063\u3066\u4e2d\u306b\u4ee5\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>api.py<\/strong><\/p>\n<div>\n<pre><strong>from fastapi import FastAPI, File, UploadFile<\/strong>\r\n<strong>from magika import Magika<\/strong>\r\n\r\n<strong>app = FastAPI()<\/strong>\r\n\r\n<strong>magika = Magika()<\/strong>\r\n\r\n<strong>@app.get(\"\/test\")<\/strong>\r\n<strong>async def test():<\/strong>\r\n<strong>    return \"test\";<\/strong>\r\n\r\n<strong>@app.post(\"\/file_type_check\")<\/strong>\r\n<strong>async def create_file(file: UploadFile = File(...)):<\/strong>\r\n<strong>    contents = await file.read()<\/strong>\r\n<strong>    return magika.identify_bytes(contents)<\/strong><\/pre>\n<\/div>\n<div>\n<p>\u306f\u3044\u2757<\/p>\n<p>\u3053\u308c\u3067\u3001<code>FastAPI<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3068\u300c<strong>http:\/\/127.0.0.1:8000\/file_type_check<\/strong>\u300d\u3078\u30d5\u30a1\u30a4\u30eb\u9001\u4fe1\u3059\u308b\u3068<code>Magika<\/code>\u3067\u5b9f\u884c\u3057\u305f\u7d50\u679c\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h1>Laravel \u306e\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u304b\u3089\u306f<code>Laravel<\/code>\u5074\u306e\u4f5c\u696d\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<pre><strong>php artisan make:rule Magika<\/strong><\/pre>\n<\/div>\n<\/div>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Rules\/Magika.php<\/strong><\/p>\n<div>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Rules;<\/strong>\r\n\r\n<strong>use Closure;<\/strong>\r\n<strong>use Illuminate\\Contracts\\Validation\\ValidationRule;<\/strong>\r\n<strong>use Illuminate\\Support\\Arr;<\/strong>\r\n<strong>use Illuminate\\Support\\Facades\\Http;<\/strong>\r\n\r\n<strong>class Magika implements ValidationRule<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    public function __construct(private array $mime_types) \/\/ \u8a31\u53ef\u3059\u308b mime-type \u3092\u6307\u5b9a\u3059\u308b<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    \/**<\/strong>\r\n<strong>     * Run the validation rule.<\/strong>\r\n<strong>     *<\/strong>\r\n<strong>     * @param  \\Closure(string): \\Illuminate\\Translation\\PotentiallyTranslatedString  $fail<\/strong>\r\n<strong>     *\/<\/strong>\r\n<strong>    public function validate(string $attribute, mixed $value, Closure $fail): void<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $fast_api_url = 'http:\/\/127.0.0.1:4989\/file_type_check'; \/\/ \u30db\u30f3\u30c8\u306f .env -&gt; config \u5316\u3059\u3079\u304d\u3067\u3059\uff01<\/strong>\r\n<strong>        $stream = fopen($value-&gt;getRealPath(), 'r+');<\/strong>\r\n\r\n<strong>        \/\/ Magika\uff08FastAPI\uff09\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u9001\u4fe1<\/strong>\r\n<strong>        $response = Http::attach('file', $stream)-&gt;post($fast_api_url);<\/strong>\r\n<strong>        $mime_type = '';<\/strong>\r\n\r\n<strong>        if($response-&gt;ok()) {<\/strong>\r\n\r\n<strong>            $response_data = $response-&gt;json();<\/strong>\r\n<strong>            $mime_type = Arr::get($response_data, 'output.mime_type');<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        if (! in_array($mime_type, $this-&gt;mime_types, true)) {<\/strong>\r\n\r\n<strong>            $fail('\u30d5\u30a1\u30a4\u30eb\u30bf\u30a4\u30d7\u300c' . $mime_type . '\u300d\u306f\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3067\u304d\u307e\u305b\u3093');<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<\/div>\n<h1>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u306e\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3067\u30c1\u30a7\u30c3\u30af\u3067\u304d\u308b\u3088\u3046\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<pre><strong>php artisan make:controller FileUploadController<\/strong><\/pre>\n<\/div>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Http\/Controllers\/FileUploadController.php<\/strong><\/p>\n<div>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Http\\Controllers;<\/strong>\r\n\r\n<strong>use Illuminate\\Http\\Request;<\/strong>\r\n<strong>use App\\Rules\\Magika;<\/strong>\r\n\r\n<strong>class FileUploadController extends Controller<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    public function create()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return view('file_upload.create');<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function store(Request $request)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $request-&gt;validate([<\/strong>\r\n<strong>            'file' =&gt; [<\/strong>\r\n<strong>                'required',<\/strong>\r\n<strong>                'file',<\/strong>\r\n<strong>                'max:5120', \/\/ 5MB<\/strong>\r\n<strong>                new Magika([ \/\/ \u3053\u3053\u3067 Magika \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30eb\u30fc\u30eb\u3092\u4f7f\u3046<\/strong>\r\n<strong>                    'image\/jpeg',<\/strong>\r\n<strong>                    'image\/png',<\/strong>\r\n<strong>                    'image\/gif',<\/strong>\r\n<strong>                ]),<\/strong>\r\n<strong>            ]<\/strong>\r\n<strong>        ]);<\/strong>\r\n\r\n<strong>        return '\u5b8c\u4e86\uff01';<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u306a\u304a\u3001<code>new Magika()<\/code>\u306e\u5f15\u6570\u3068\u3057\u3066\u30bb\u30c3\u30c8\u3057\u3066\u3044\u308b\u4ee5\u4e0b\uff13\u3064\u306e<code>mime-type<\/code>\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u300c\u901a\u904e\u3067\u304d\u308b\u300d\u3082\u306e\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>image\/jpeg<\/li>\n<li>image\/png<\/li>\n<li>image\/gif<\/li>\n<\/ul>\n<p>\u3064\u307e\u308a\u3001\u30d3\u30c3\u30c8\u30de\u30c3\u30d7\u3084<code>webp<\/code>\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<\/div>\n<h1>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5185\u3067\u30bb\u30c3\u30c8\u3057\u305f\u30d3\u30e5\u30fc\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div>\n<pre><strong>php artisan make:view file_upload.create<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>resources\/views\/file_upload\/create.blade.php<\/strong><\/p>\n<div>\n<pre><strong>&lt;html&gt;<\/strong>\r\n<strong>&lt;head&gt;<\/strong>\r\n<strong>    &lt;title&gt;Magika \u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u30fb\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3&lt;\/title&gt;<\/strong>\r\n<strong>    &lt;script src=\"https:\/\/cdn.tailwindcss.com\/3.4.1\"&gt;&lt;\/script&gt;<\/strong>\r\n<strong>&lt;\/head&gt;<\/strong>\r\n<strong>&lt;body&gt;<\/strong>\r\n<strong>    &lt;div class=\"p-5\"&gt;<\/strong>\r\n<strong>        &lt;form action=\"{{ route('file_upload.store') }}\" method=\"post\" enctype=\"multipart\/form-data\"&gt;<\/strong>\r\n<strong>            @csrf<\/strong>\r\n<strong>            &lt;div class=\"mb-3\"&gt;<\/strong>\r\n<strong>                &lt;input type=\"file\" name=\"file\"&gt;<\/strong>\r\n<strong>            &lt;\/div&gt;<\/strong>\r\n<strong>            @error('file')<\/strong>\r\n<strong>                &lt;div class=\"text-red-500 bg-red-100 p-3 mb-4 rounded\"&gt;{{ $message }}&lt;\/div&gt;<\/strong>\r\n<strong>            @enderror<\/strong>\r\n<strong>            &lt;button type=\"submit\" class=\"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded\"&gt;\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9&lt;\/button&gt;<\/strong>\r\n<strong>        &lt;\/form&gt;<\/strong>\r\n<strong>    &lt;\/div&gt;<\/strong>\r\n<strong>&lt;\/body&gt;<\/strong>\r\n<strong>&lt;\/html&gt;<\/strong><\/pre>\n<\/div>\n<\/div>\n<h1>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6700\u5f8c\u306b\u30eb\u30fc\u30c8\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>routes\/web.php<\/strong><\/p>\n<div>\n<pre><strong>use App\\Http\\Controllers\\FileUploadController;<\/strong>\r\n\r\n\/\/ \u7701\u7565\r\n\r\n<strong>Route::prefix('file_upload')-&gt;controller(FileUploadController::class)-&gt;group(function(){<\/strong>\r\n\r\n<strong>    Route::get('create', 'create')-&gt;name('file_upload.create');<\/strong>\r\n<strong>    Route::post('store', 'store')-&gt;name('file_upload.store');<\/strong>\r\n\r\n<strong>});<\/strong><\/pre>\n<\/div>\n<p>\u3053\u308c\u3067\u4f5c\u696d\u306f\u5b8c\u4e86\u3067\u3059\uff01<br \/>\n\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\u3002\ud83d\ude04\u2728<\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p>\u307e\u305a\u306f<code>Python<\/code>\u306e<code>FastAPI<\/code>\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<div>\n<pre><strong>uvicorn api:app --port 4989 --reload<\/strong><\/pre>\n<p>\u203b \u79c1\u306e\u74b0\u5883\u3067\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u306e<code>8000<\/code>\u30dd\u30fc\u30c8\u304c\u4f7f\u7528\u3055\u308c\u3066\u3044\u305f\u306e\u3067\u30dd\u30fc\u30c8\u756a\u53f7\u3092\u5909\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>FastAPI<\/code>\u304c\u5f85\u6a5f\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12474\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_3.png\" alt=\"\" width=\"610\" height=\"141\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_3.png 610w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_3-300x69.png 300w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>\u3067\u306f\u3001\u6b21\u306b<code>Laravel<\/code>\u5074\u3067\u3059\u3002<br \/>\n\u300c<strong>https:\/\/******\/file_upload\/create<\/strong>\u300d\u3078\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12475\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_4.png\" alt=\"\" width=\"340\" height=\"119\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_4.png 340w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_4-300x105.png 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/p>\n<\/div>\n<p>\u30d5\u30a9\u30fc\u30e0\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n\u3067\u306f\u3001\u307e\u305a\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u8a31\u53ef\u3055\u308c\u3066\u3044\u306a\u3044<code>webp<\/code>\u753b\u50cf\u3092\u9001\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12476\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_5.png\" alt=\"\" width=\"366\" height=\"120\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_5.png 366w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_5-300x98.png 300w\" sizes=\"auto, (max-width: 366px) 100vw, 366px\" \/><\/p>\n<p>\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12477\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_6.png\" alt=\"\" width=\"497\" height=\"186\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_6.png 497w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_6-300x112.png 300w\" sizes=\"auto, (max-width: 497px) 100vw, 497px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u671f\u5f85\u901a\u308a\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u8a31\u53ef\u3055\u308c\u3066\u3044\u308b<code>jpg<\/code>\u753b\u50cf\u3092\u9001\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12478\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2024\/02\/magika_laravel_validation_7.png\" alt=\"\" width=\"67\" height=\"44\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u3053\u3061\u3089\u3082\u60f3\u5b9a\u901a\u308a\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3059\u3079\u3066\u6210\u529f\u3067\u3059\ud83d\ude04\u2728<\/p>\n<h1>\u4f01\u696d\u69d8\u3078\u306e\u3054\u63d0\u6848<\/h1>\n<p><code>Magika<\/code>\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u3088\u308a\u7cbe\u5ea6\u306e\u9ad8\u3044\u30d5\u30a1\u30a4\u30eb\u30bf\u30a4\u30d7\u5224\u5225\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3055\u3089\u306b<code>Magika<\/code>\u306f\u9ad8\u901f\u3067\u52d5\u304f\uff08\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u8aac\u660e\u6587\u3067\u306f\u300c\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5927\u304d\u304f\u3066\u3082\u9ad8\u901f\u3067\u52d5\u304f\u300d\u3068\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\uff09\u306e\u3067\u3001\u52d5\u753b\u306a\u3069\u3067\u3082\u3042\u308b\u7a0b\u5ea6\u306f\u65e9\u304f\u51e6\u7406\u304c\u3067\u304d\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3082\u3057\u305d\u3046\u3044\u3063\u305f\u6a5f\u80fd\u3092\u3054\u5e0c\u671b\u3067\u3057\u305f\u3089\u3001\u3044\u3064\u3067\u3082\u304a\u6c17\u8efd\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u304a\u5f85\u3061\u3057\u3066\u304a\u308a\u307e\u3059\u3002\ud83d\ude04\u2728<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Magika<\/code>\u3092\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u5316\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u6b63\u76f4\u8a00\u3046\u3068\u3001<code>PHP<\/code>\u3067\u3082\u76f4\u63a5\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u307b\u3057\u3044\u306a\u3068\u3044\u3046\u6c17\u6301\u3061\u3067\u3059\u304c\u3001<code>FastAPI<\/code>\u304c\u3042\u308c\u3070\u3059\u3050\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3057\u3001<code>API<\/code>\u30ad\u30fc\u307f\u305f\u3044\u306a\u3082\u306e\u3092\u4f5c\u3063\u3066\u304a\u3051\u3070\u4ed6\u306e\u4eba\u306b\u52dd\u624b\u306b\u4f7f\u308f\u308c\u308b\u3053\u3068\u3082\u306a\u3044\u306e\u3067\u3001\u8907\u6570\u30b5\u30a4\u30c8\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b<code>Magika<\/code>\u5c02\u7528\u306e<code>API<\/code>\u3092\u4f5c\u3063\u3066\u304a\u3044\u3066\u3082\u826f\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u7a7a\u306b\u3057\u3066\u9001\u4fe1\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001\u300c<strong>inode\/x-empty<\/strong>\u300d\u3068\u3044\u3046<code>mime-type<\/code>\u304c\u8fd4\u3063\u3066\u304d\u305f\u306e\u3067\u3001\u3082\u3057\u304b\u3059\u308b\u3068\u3044\u308d\u3093\u306a\u4f8b\u5916\u30bf\u30a4\u30d7\u304c\u3042\u308b\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u305c\u3072\u307f\u306a\u3055\u3093\u3082<code>Magika<\/code>\u3067\u904a\u3093\u3067\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11002 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/no_10.png\" alt=\"\" width=\"370\" height=\"290\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/no_10.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/no_10-300x235.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/>\u300c\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u306e\u300e\u30da\u30eb\u30bd\u30ca\u300f<br \/>\n\u3092\u8abf\u3079\u3066\u305f\u3089\u3001\u30b2\u30fc\u30e0\u306e\u65b9\u304c<br \/>\n\u51fa\u3066\u304f\u308b\u3093\u3067\u3059\u304c\u2026\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3044\u3064\u3082\u306f\u30a8\u30c3\u30af\u30b9\u304b\u3089\u65b0\u3057\u3044\u30c6\u30af\u30ce\u30ed\u30b8\u30fc\u306e\u60c5\u5831\u3092\u5f97\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3082\u3046\uff11\u3064\u79c1\u304c\u60c5\u5831\u6e90\u306b\u3057\u3066\u3044\u308b\u306e\u304c\u30cb\u30e5\u30fc\u30b9\u30a2\u30d7\u30ea\u3067\u3059\u3002 \u904e\u53bb\u306e\u95b2\u89a7\u60c5\u5831\u304b\u3089\u300c\u3053\u308c\u3001\u3069\u3046\u305b\u597d &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=12469\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Magika + Laravel \u3067\u6b63\u78ba\u306a\u30d5\u30a1\u30a4\u30eb\u30bf\u30a4\u30d7\u5224\u5225\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":12482,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-12469","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/12469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12469"}],"version-history":[{"count":5,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/12469\/revisions"}],"predecessor-version":[{"id":12484,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/12469\/revisions\/12484"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/12482"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}