File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,12 @@ and it can add headers array by optional
6969
7070 return $entry->response($filename, ['Content-Disposition', 'attachement']);
7171
72+ ### Parse File Path to URL
73+ if you store your file into cloud storage and you want to get url cloud site,
74+ you can use url() method to get it
75+
76+ $entry->url('wfjsdf.jpg'); // => "https://s3-ap-northeast-1.amazonaws.com/xxx/xxx/55c1e027caa62L.png"
77+
7278### Work with Laravel Storage
7379
7480* Get file content
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ public function __construct($basepath = '/')
1515 $ basepath .= '/ ' ;
1616 }
1717
18+ if (mb_substr ($ basepath , 0 , 1 , 'utf8 ' ) == '/ ' ) {
19+ $ basepath = mb_substr ($ basepath , 1 , null , 'utf8 ' );
20+ }
21+
1822 $ this ->basepath = $ basepath ;
1923 }
2024
@@ -53,6 +57,18 @@ public function fullpath($filename)
5357 return $ this ->basepath . $ filename ;
5458 }
5559
60+ public function url ($ filename )
61+ {
62+ if (\Config::get ('filesystems.default ' ) == 's3 ' ) {
63+ return \Storage::getDriver ()->getAdapter ()->getClient ()->getObjectUrl (
64+ \Storage::getDriver ()->getAdapter ()->getBucket (),
65+ $ this ->basepath . $ filename
66+ );
67+ } else {
68+ return $ this ->basepath . $ filename ;
69+ }
70+ }
71+
5672 public function response ($ filename , $ headers = [])
5773 {
5874 try {
You can’t perform that action at this time.
0 commit comments