{"id":8993,"date":"2025-02-04T12:33:47","date_gmt":"2025-02-04T03:33:47","guid":{"rendered":"https:\/\/www.gesource.jp\/weblog\/?p=8993"},"modified":"2025-02-02T23:34:33","modified_gmt":"2025-02-02T14:34:33","slug":"laravel%e3%81%a7storage%e3%81%aetemporaryurl%e3%82%92%e3%83%a2%e3%83%83%e3%82%af%e5%8c%96%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.gesource.jp\/weblog\/?p=8993","title":{"rendered":"Laravel\u3067Storage\u306etemporaryUrl\u3092\u30e2\u30c3\u30af\u5316\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Laravel\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3068\u3001S3\u30b9\u30c8\u30ec\u30fc\u30b8\u306e<code>temporaryUrl<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u5834\u9762\u304c\u51fa\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u74b0\u5883\u3067\u306f\u5b9f\u969b\u306eS3\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u3053\u306e<code>temporaryUrl<\/code>\u3092\u30e2\u30c3\u30af\u5316\u3057\u3066\u30c6\u30b9\u30c8\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001Laravel\u306e<code>Storage<\/code>\u30d5\u30a1\u30b5\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066<code>temporaryUrl<\/code>\u3092\u30e2\u30c3\u30af\u5316\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h2>\u52d5\u6a5f<\/h2>\n<p>\u901a\u5e38\u3001<code>Storage<\/code>\u306e<code>temporaryUrl<\/code>\u306f\u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3059\u308b\u4e00\u6642\u7684\u306a\u30a2\u30af\u30bb\u30b9URL\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3067\u306f\u5916\u90e8\u30b5\u30fc\u30d3\u30b9\uff08\u3053\u306e\u5834\u5408\u306fAWS S3\uff09\u306b\u4f9d\u5b58\u3059\u308b\u3053\u3068\u306a\u304f\u30c6\u30b9\u30c8\u3092\u5b8c\u7d50\u3055\u305b\u305f\u3044\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001<code>temporaryUrl<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u30e2\u30c3\u30af\u5316\u3057\u3001\u610f\u56f3\u3057\u305f\u5024\u3092\u8fd4\u3059\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30e2\u30c3\u30af\u5316\u306e\u624b\u9806<\/h2>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u30b9\u30cb\u30da\u30c3\u30c8\u306f\u3001<code>Storage<\/code>\u30d5\u30a1\u30b5\u30fc\u30c9\u3092\u30e2\u30c3\u30af\u5316\u3057\u3001<code>temporaryUrl<\/code>\u30e1\u30bd\u30c3\u30c9\u304c\u6307\u5b9a\u3057\u305fURL\u3092\u8fd4\u3059\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-php\">Storage::shouldReceive('disk')\n        -&gt;with('s3')\n        -&gt;andReturnSelf();\n\nStorage::shouldReceive('temporaryUrl')\n        -&gt;with('example.jpg', Mockery::type(\\DateTimeInterface::class))\n        -&gt;andReturn('https:\/\/example.com\/temp-url\/example.jpg');\n<\/code><\/pre>\n<h3>\u89e3\u8aac<\/h3>\n<ol>\n<li><code>Storage::shouldReceive('disk')-&gt;with('s3')-&gt;andReturnSelf();<\/code><br \/>\n<code>Storage::disk('s3')<\/code>\u304c\u547c\u3073\u51fa\u3055\u308c\u305f\u3068\u304d\u306b\u3001<code>Storage<\/code>\u306e\u30e2\u30c3\u30af\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u81ea\u8eab\u3092\u8fd4\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30c1\u30a7\u30fc\u30f3\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u969b\u306b\u30e2\u30c3\u30af\u3092\u9069\u5207\u306b\u52d5\u4f5c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<\/li>\n<li>\n<p><code>Storage::shouldReceive('temporaryUrl')<\/code><br \/>\n<code>temporaryUrl<\/code>\u304c\u547c\u3073\u51fa\u3055\u308c\u305f\u3068\u304d\u306b\u3001\u6307\u5b9a\u3057\u305fURL\u3092\u8fd4\u3059\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u5f15\u6570\u3068\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u540d\uff08<code>example.jpg<\/code>\uff09\u3068<code>DateTimeInterface<\/code>\u578b\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u671f\u5f85\u3055\u308c\u307e\u3059\u3002<\/p>\n<\/li>\n<\/ol>\n<h2>\u30e2\u30c3\u30af\u5316\u3092\u6d3b\u7528\u3057\u305f\u30c6\u30b9\u30c8\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u306f\u3001<code>Storage<\/code>\u306e<code>temporaryUrl<\/code>\u3092\u30e2\u30c3\u30af\u5316\u3057\u3001\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3067\u5229\u7528\u3059\u308b\u4f8b\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-php\">public function testTemporaryUrl()\n{\n    \/\/ \u30e2\u30c3\u30af\u8a2d\u5b9a\n    Storage::shouldReceive('disk')\n        -&gt;with('s3')\n        -&gt;andReturnSelf();\n\n    Storage::shouldReceive('temporaryUrl')\n        -&gt;with('example1.jpg', Mockery::type(DateTimeInterface::class))\n        -&gt;andReturn('https:\/\/example.com\/temp-url\/example1.jpg');\n\n    Storage::shouldReceive('temporaryUrl')\n        -&gt;with('example2.jpg', Mockery::type(DateTimeInterface::class))\n        -&gt;andReturn('https:\/\/example.com\/temp-url\/example2.jpg');\n\n    \/\/ \u30c6\u30b9\u30c8: \u30e2\u30c3\u30af\u5316\u3055\u308c\u305fURL\u306e\u78ba\u8a8d\n    $url = Storage::disk('s3')-&gt;temporaryUrl('example1.jpg', now()-&gt;addMinutes(5));\n    $this-&gt;assertEquals('https:\/\/example.com\/temp-url\/example1.jpg', $url);\n\n    $url = Storage::disk('s3')-&gt;temporaryUrl('example2.jpg', now()-&gt;addMinutes(5));\n    $this-&gt;assertEquals('https:\/\/example.com\/temp-url\/example2.jpg', $url);\n}\n<\/code><\/pre>\n<h3>\u30c6\u30b9\u30c8\u306e\u30dd\u30a4\u30f3\u30c8<\/h3>\n<ul>\n<li>\u30e2\u30c3\u30af\u5316\u306b\u3088\u308a\u3001\u5b9f\u969b\u306bAWS S3\u306b\u63a5\u7d9a\u3059\u308b\u3053\u3068\u306a\u304f\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u65e5\u4ed8\u306e\u5f15\u6570\u3054\u3068\u306b\u8fd4\u3055\u308c\u308bURL\u3092\u81ea\u7531\u306b\u8a2d\u5b9a\u53ef\u80fd\u3067\u3059\u3002<\/li>\n<li>\u30c6\u30b9\u30c8\u306e\u7d50\u679c\u3092\u4fdd\u8a3c\u3059\u308b\u305f\u3081\u3001\u30e2\u30c3\u30af\u5316\u3057\u305fURL\u3092<code>assertEquals<\/code>\u3067\u691c\u8a3c\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>Laravel\u306e\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3067\u5916\u90e8\u30b9\u30c8\u30ec\u30fc\u30b8\u306e\u4f9d\u5b58\u3092\u6392\u9664\u3059\u308b\u3053\u3068\u306f\u3001\u30c6\u30b9\u30c8\u306e\u4fe1\u983c\u6027\u3068\u30b9\u30d4\u30fc\u30c9\u3092\u5411\u4e0a\u3055\u305b\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u7d39\u4ecb\u3057\u305f\u65b9\u6cd5\u3092\u6d3b\u7528\u3059\u308c\u3070\u3001\u7c21\u5358\u306b<code>temporaryUrl<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u30e2\u30c3\u30af\u5316\u3067\u304d\u3001\u30b9\u30c8\u30ec\u30fc\u30b8\u95a2\u9023\u306e\u30b3\u30fc\u30c9\u3092\u52b9\u7387\u3088\u304f\u30c6\u30b9\u30c8\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3068\u3001S3\u30b9\u30c8\u30ec\u30fc\u30b8\u306etemporaryUrl\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u5834\u9762\u304c\u51fa\u3066\u304d\u307e\u3059\u3002 \u3057\u304b\u3057\u3001\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u74b0\u5883\u3067\u306f\u5b9f\u969b\u306eS3\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u3053\u306etemporaryUrl\u3092\u30e2\u30c3\u30af\u5316\u3057\u3066\u30c6 &#8230;<\/p>\n<p><a href=\"https:\/\/www.gesource.jp\/weblog\/?p=8993\" class=\"more-link\">Continue reading &lsquo;Laravel\u3067Storage\u306etemporaryUrl\u3092\u30e2\u30c3\u30af\u5316\u3059\u308b\u65b9\u6cd5&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[25],"tags":[186,151],"class_list":["post-8993","post","type-post","status-publish","format-standard","hentry","category-php","tag-laravel","tag-php"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/8993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8993"}],"version-history":[{"count":0,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/8993\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}