PHP code example of triginarsa / minio-storage-utils
1. Go to this page and download the library: Download triginarsa/minio-storage-utils library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Get URL for existing file (uses config defaults)
$url = MinioStorage::getUrl('path/to/file.jpg'); // result: "http://your-minio-server/your-bucket/img/avatar.png"
// Get signed URL with custom expiration
$signedUrl = MinioStorage::getUrl('path/to/file.jpg', 3600, true); // 1 hour, signed
// Get public URL (no expiration, no signature)
$publicUrl = MinioStorage::getUrl('path/to/file.jpg', null, false);
// or
$publicUrl = MinioStorage::getPublicUrl('path/to/file.jpg');
use Triginarsa\MinioStorageUtils\Laravel\Facades\MinioStorage;
public function view(Request $request)
{
$request->validate(['imagePath' => 'ePath)){
return response()->json(['success => false', 'message' => 'File not found'], 404)
}
$result = MinioStorage::getUrl($imagePath);
return response()->json([
'success' => true,
'image_url' => $result, // "http://your-minio-server/your-bucket/img/avatar-1.png"
]);
}
use Triginarsa\MinioStorageUtils\Laravel\Facades\MinioStorage;
public function publicUrl(string $filePath)
{
try {
// Optionally disable existence check: getUrlPublic($filePath, null, false)
$result = MinioStorage::getUrlPublic($filePath);
return $result;
} catch (\Throwable $e) {
return 'img/default.png';
}
}
use Triginarsa\MinioStorageUtils\Laravel\Facades\MinioStorage;
public function publicUrlFromOtherBucket(string $filePath, string $bucket)
{
try {
// Pass the target bucket as the 2nd argument (3rd arg disables the existence check)
return MinioStorage::getUrlPublic($filePath, $bucket, false);
} catch (\Throwable $e) {
return 'img/default.png';
}
}
// The default `getUrl()` call now returns a public URL
$publicUrl = MinioStorage::getUrl('path/to/file.jpg');
// You can also be explicit
$publicUrl = MinioStorage::getUrl('path/to/file.jpg', null, false);
$publicUrl = MinioStorage::getPublicUrl('path/to/file.jpg');
// Explicitly request a signed URL with a 1-hour expiration
$signedUrl = MinioStorage::getUrl('path/to/file.jpg', 3600, true);