File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 3
3
namespace CloudinaryLabs \CloudinaryLaravel ;
4
4
5
5
use Cloudinary \Cloudinary ;
6
+ use Cloudinary \Api \Exception \NotFound ;
6
7
use League \Flysystem \Adapter \Polyfill \NotSupportingVisibilityTrait ;
7
8
use League \Flysystem \AdapterInterface ;
8
9
use League \Flysystem \Config ;
10
+ use Illuminate \Support \Str ;
9
11
10
12
11
13
/**
@@ -404,4 +406,24 @@ public function getTimestamp($path)
404
406
{
405
407
return $ this ->prepareTimestamp ($ this ->getResource ($ path ));
406
408
}
409
+
410
+ /**
411
+ * Get the url of a file
412
+ *
413
+ * @param string $path
414
+ *
415
+ * @return string|false
416
+ */
417
+ public function getUrl ($ path )
418
+ {
419
+ if ($ path == '/ ' ) {
420
+ return $ path ;
421
+ }
422
+ try {
423
+ $ resource = $ this ->getResource (Str::beforeLast ($ path , '. ' ));
424
+ return $ resource ['secure_url ' ] ?? '' ;
425
+ } catch (NotFound $ e ) {
426
+ return '' ;
427
+ }
428
+ }
407
429
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Orchestra \Testbench \TestCase ;
4
+ use Illuminate \Http \UploadedFile ;
5
+ use Illuminate \Database \Eloquent \Model ;
6
+ use CloudinaryLabs \CloudinaryLaravel \MediaAlly ;
7
+ use CloudinaryLabs \CloudinaryLaravel \CloudinaryEngine ;
8
+ use Illuminate \Support \Facades \Storage ;
9
+
10
+ /**
11
+ *
12
+ */
13
+ class CloudinaryAdapterTest extends TestCase
14
+ {
15
+
16
+ protected function setUp (): void
17
+ {
18
+ parent ::setUp ();
19
+ }
20
+
21
+ protected function getEnvironmentSetup ($ app )
22
+ {
23
+ $ app ['config ' ]->set ('cloudinary.cloud_url ' , env ('CLOUDINARY_URL ' ));
24
+ }
25
+
26
+ protected function getPackageProviders ($ app )
27
+ {
28
+ return ['CloudinaryLabs\CloudinaryLaravel\CloudinaryServiceProvider ' ];
29
+ }
30
+
31
+ public function test_can_get_url_given_public_id ()
32
+ {
33
+ //file already exists
34
+ $ this ->assertEquals ('https://res.cloudinary.com/dwinzyahj/image/upload/v1616774832/sample_qgqooj.jpg ' , Storage::disk ('cloudinary ' )->url ('sample_qgqooj.jpg ' ));
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments