|
1 | | -## FileEntry API |
| 1 | +## Laravel File API |
2 | 2 |
|
3 | 3 | ### Introduction |
4 | 4 |
|
5 | | -FileEntry API is good way to handle files with Laravel Storage. |
| 5 | +Laravel File API is good way to handle files with Laravel Storage. |
6 | 6 |
|
7 | | -### Install FileEntry |
| 7 | +### Install File API |
8 | 8 |
|
9 | 9 | composer.json: |
10 | 10 |
|
11 | 11 | "require" : { |
12 | | - "unisharp/laravel-fileentry" : "dev-master" |
| 12 | + "unisharp/laravel-fileapi" : "dev-master" |
13 | 13 | }, |
14 | 14 | "repositories": { |
15 | 15 | "type": "git", |
16 | | - "url": "https://github.com/UniSharp/laravel-fileentry.git |
| 16 | + "url": "https://github.com/UniSharp/laravel-fileapi.git |
17 | 17 | } |
18 | 18 |
|
19 | 19 | save it and then |
20 | 20 |
|
21 | 21 | composer update |
22 | 22 |
|
23 | | -### Initialize FileEntry |
| 23 | +### Initialize File API |
24 | 24 |
|
25 | | - use \Unisharp\FileEntry\FileEntry; |
| 25 | + use \Unisharp\FileApi\FileApi; |
26 | 26 |
|
27 | | - $entry = new FileEntry(); |
| 27 | + $fa = new FileApi(); |
28 | 28 |
|
29 | 29 | or |
30 | 30 |
|
31 | | - $entry = new FileEntry('/images'); # initialize it by giving a base path |
| 31 | + $fa = new FileApi('/images'); # initialize it by giving a base path |
32 | 32 |
|
33 | 33 |
|
34 | 34 | ### Save to Storage By Giving Lravel Upload File |
|
37 | 37 |
|
38 | 38 | get unique filename |
39 | 39 |
|
40 | | - $file = $entry->save(\Input::file('image')); // => wfj412.jpg |
| 40 | + $file = $fa->save(\Input::file('image')); // => wfj412.jpg |
41 | 41 |
|
42 | 42 | or input files is an array |
43 | 43 |
|
44 | 44 | $files = []; |
45 | 45 | foreach (\Input::file('images') as $file) { |
46 | | - $files []= $entry->save('images'); |
| 46 | + $files []= $fa->save('images'); |
47 | 47 | } |
48 | 48 |
|
49 | 49 | * Custimize your upload file name |
50 | 50 |
|
51 | | - $file = $entry->save('image', 'custimized_filename'); // => custimized_filename.jpg |
| 51 | + $file = $fa->save('image', 'custimized_filename'); // => custimized_filename.jpg |
52 | 52 | |
53 | 53 |
|
54 | 54 | ### Get file fullpath |
55 | 55 |
|
56 | | - $entry->fullpath('wfj412.jpg'); // => '/images/wfj412.jpg' |
| 56 | + $fa->getFullPath('wfj412.jpg'); // => '/images/wfj412.jpg' |
57 | 57 |
|
58 | 58 | ### Routing your files |
59 | 59 |
|
60 | | -All uploaded files cannot found in public folder, because FileEntry use Laravel Storage to store them. |
| 60 | +All uploaded files cannot found in public folder, because FileApi use Laravel Storage to store them. |
61 | 61 | You can write a routing rules to get it. it will response file content and use http cache by default. |
62 | 62 |
|
63 | 63 | Route::get('/upload/{filename}', function ($filename) { |
64 | | - $entry = new FileEntry(); |
65 | | - return $entry->response($filename); |
| 64 | + $fa = new FileApi(); |
| 65 | + return $fa->getResponse($filename); |
66 | 66 | }); |
67 | 67 |
|
68 | 68 | and it can add headers array by optional |
69 | 69 |
|
70 | | - return $entry->response($filename, ['Content-Disposition', 'attachement']); |
| 70 | + return $fa->getResponse($filename, ['Content-Disposition', 'attachement']); |
71 | 71 |
|
72 | 72 | ### Parse File Path to URL |
73 | 73 | if you store your file into cloud storage and you want to get url cloud site, |
74 | 74 | you can use url() method to get it |
75 | 75 |
|
76 | | - $entry->url('wfjsdf.jpg'); // => "https://s3-ap-northeast-1.amazonaws.com/xxx/xxx/55c1e027caa62L.png" |
| 76 | + echo $fa->getUrl('wfjsdf.jpg'); // => "https://s3-ap-northeast-1.amazonaws.com/xxx/xxx/55c1e027caa62L.png" |
77 | 77 |
|
78 | 78 | ### Work with Laravel Storage |
79 | 79 |
|
80 | 80 | * Get file content |
81 | 81 |
|
82 | | - \Storage::get($entry->fullpath('wfj412.jpg')); |
| 82 | + \Storage::get($fa->getPath('wfj412.jpg')); |
83 | 83 | |
84 | 84 | * Write files |
85 | 85 |
|
86 | | - \Storage::put($entry->fullpath('wfj412.jpg')); |
| 86 | + \Storage::put($fa->getPath('wfj412.jpg')); |
87 | 87 | |
88 | 88 | * Get Mime Type |
89 | 89 |
|
90 | | - \Storage::mimeType($entry->fullpath('wfj412.jpg')); |
| 90 | + \Storage::mimeType($fa->getPath('wfj412.jpg')); |
91 | 91 |
|
0 commit comments