@@ -8,9 +8,7 @@ Laravel File API is good way to handle files with Laravel Storage.
88
991 . Install File API
1010
11- ``` php
1211 composer require unisharp/laravel-fileapi
13- ```
1412
15131 . Set service provider in ` config/app.php `
1614
@@ -20,78 +18,120 @@ Laravel File API is good way to handle files with Laravel Storage.
2018
21191. publish config file
2220
23- ```php
2421 php artisan vendor:publish --tag=fileapi_config
25- ```
2622
2723### Config
2824
29- 1. fill in the storage path, it will generate routes for your files.
25+ in `config/fileapi.php`
26+
27+ 1. fill in the storage path, which make routes for you.
28+
29+ ```php
30+ 'path' => ['/images/event/', '/images/article/'],
31+ ```
3032
31- 'path' => ['/images/event/'],
33+ it will generate routes like below :
34+
35+ ```php
36+ Route::get('/images/event/{filename}', function ($filename) {
37+ $entry = new \Unisharp\FileApi\FileApi('/images/event/');
38+ return $entry->getResponse($filename);
39+ });
40+
41+ Route::get('/images/article/{filename}', function ($filename) {
42+ $entry = new \Unisharp\FileApi\FileApi('/images/article/');
43+ return $entry->getResponse($filename);
44+ });
45+ ```
3246
33471. set default thumb sizes(by key and value)
3448
49+ ```php
3550 'default_thumbs' => ['S' => '96x96', 'M' => '256x256', 'L' => '480x480'],
51+ ```
3652
3753### Initialize File API
3854
55+ ```php
3956 use \Unisharp\FileApi\FileApi;
4057
4158 $fa = new FileApi();
59+ ```
4260
4361or
4462
45- $fa = new FileApi('/images'); # initialize it by giving a base path
63+ ``` php
64+ $fa = new FileApi('/images/event/'); # initialize it by giving a base path
65+ $fa_article = new FileApi('/images/article/'); # initiate another instance
66+ ```
4667
4768
4869### Save to Storage By Giving Uploaded File
4970
5071* Default Usage : get unique filename
5172
52- $file = $fa->save(\Input::file('image')); // => wfj412.jpg
73+ ``` php
74+ $file = $fa->save(\Input::file('main_image')); // => wfj412.jpg
75+ ```
5376
5477* Custimize your upload file name
5578
56- $file = $fa->save(\Input::file('image'), 'custimized_filename'); // => custimized_filename.jpg
79+ ```php
80+ $file = $fa->save(\Input::file('main_image'), 'custimized_filename'); // => custimized_filename.jpg
81+ ```
5782
5883### Save thumbnails
5984
6085* By default will set three thumbs(equal scaling)
6186
62- $file = $fa->save(\Input::file('image'));
87+ ```php
88+ $file = $fa->save(\Input::file('main_image'));
89+ ```
6390
6491* Set custom thumb sizes
6592
93+ ```php
6694 $file = $fa
6795 ->thumbs(['S' => '150x100', 'M' => '300x200', 'L' => '450x300'])
68- ->save(\Input::file('image'));
96+ ->save(\Input::file('main_image'));
97+ ```
6998
7099* make cropped thumbs
71100
72- $file = $fa->crop()->save(\Input::file('image'));
101+ ```php
102+ $file = $fa->crop()->save(\Input::file('main_image'));
103+ ```
73104
74105### Get file fullpath (abstract path from Laravel Storage)
75106
76- $fa->getPath('wfj412.jpg'); // => '/images/wfj412.jpg'
107+ ```php
108+ $fa->getPath('wfj412.jpg'); // => '/images/event/wfj412.jpg'
109+ ```
77110
78111### Parse File Path to URL
79112if you store your file into cloud storage and you want to get url cloud site,
80113you can use url() method to get it
81114
115+ ``` php
82116 echo $fa->getUrl('wfjsdf.jpg'); // => "https://s3-ap-northeast-1.amazonaws.com/xxx/xxx/55c1e027caa62L.png"
117+ ```
83118
84119### Work with Laravel Storage
85120
86121* Get file content
87122
123+ ``` php
88124 \Storage::get($fa->getPath('wfj412.jpg'));
125+ ```
89126
90127* Write files
91128
129+ ```php
92130 \Storage::put($fa->getPath('wfj412.jpg'));
131+ ```
93132
94133* Get Mime Type
95134
135+ ```php
96136 \Storage::mimeType($fa->getPath('wfj412.jpg'));
97-
137+ ```
0 commit comments