error get public url
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Helpers;
|
|||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class NextCloudHelper
|
class NextCloudHelper
|
||||||
{
|
{
|
||||||
@@ -102,17 +103,51 @@ class NextCloudHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function getFileUrl($filePath)
|
public static function getFileUrl($filePath)
|
||||||
{
|
{
|
||||||
$baseUrl = env('NEXT_CLOUD_URL');
|
$baseUrl = env('NEXT_CLOUD_URL');
|
||||||
$username = env('NEXT_CLOUD_USERNAME');
|
$publicToken = '5ogLDbQEbEMsAbD'; // Replace with your actual token
|
||||||
|
$relativePath = "/mktia/public.php/webdav/" . ltrim($filePath, '/');
|
||||||
|
|
||||||
// Build the user-specific WebDAV file URL
|
// Build the full URL
|
||||||
$relativePath = "/mktia/remote.php/dav/files/{$username}/" . ltrim($filePath, '/');
|
$url = rtrim($baseUrl, '/') . $relativePath . "?token={$publicToken}";
|
||||||
|
|
||||||
// Return the full accessible URL
|
// Initialize cURL
|
||||||
return rtrim($baseUrl, '/') . '/' . $relativePath;
|
$ch = curl_init($url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'OCS-APIRequest: true', // Ensure Nextcloud recognizes the API request
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
// Handle cURL errors
|
||||||
|
if ($response === false) {
|
||||||
|
$error = curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
throw new \Exception("cURL error: {$error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNextcloudFile($filePath)
|
||||||
|
{
|
||||||
|
// Check if the file exists
|
||||||
|
if (Storage::disk('webdav')->exists($filePath)) {
|
||||||
|
// Get the file contents
|
||||||
|
$content = Storage::disk('webdav')->get($filePath);
|
||||||
|
|
||||||
|
// Return the file as a response for download
|
||||||
|
return response($content)
|
||||||
|
->header('Content-Type', 'application/pdf')
|
||||||
|
->header('Content-Disposition', 'inline; filename="' . basename($filePath) . '"');
|
||||||
|
} else {
|
||||||
|
return response()->json(['error' => 'File not found'], 404);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"laravel/tinker": "^2.9",
|
"laravel/tinker": "^2.9",
|
||||||
"laravel/ui": "^4.6",
|
"laravel/ui": "^4.6",
|
||||||
"laravolt/avatar": "^6.0",
|
"laravolt/avatar": "^6.0",
|
||||||
|
"league/flysystem-webdav": "^3.29",
|
||||||
"nino/laravel-nextcloud-fs": "^2.0",
|
"nino/laravel-nextcloud-fs": "^2.0",
|
||||||
"phpoffice/phpspreadsheet": "^3.5",
|
"phpoffice/phpspreadsheet": "^3.5",
|
||||||
"singlequote/laravel-webdav": "^1.1",
|
"singlequote/laravel-webdav": "^1.1",
|
||||||
|
|||||||
Generated
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "83771e2a711327eac79ef3f7b30673da",
|
"content-hash": "fc2177036b736100113a527777c8cbc8",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "barryvdh/laravel-dompdf",
|
"name": "barryvdh/laravel-dompdf",
|
||||||
|
|||||||
@@ -68,6 +68,16 @@ return [
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'webdav' => [
|
||||||
|
'driver' => 'webdav',
|
||||||
|
'baseUri' => 'https://mkt.tunggal-pharma.com/mktia/remote.php/dav/files/user_dev/',
|
||||||
|
'userName' => env('NEXT_CLOUD_USERNAME'),
|
||||||
|
'password' => env('NEXT_CLOUD_PASSWORD'),
|
||||||
|
'prefix' => '',
|
||||||
|
'options' => [
|
||||||
|
'verify' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -115,7 +115,7 @@
|
|||||||
<td>{{ number_format($item->total, 0, ',', '.') }}</td>
|
<td>{{ number_format($item->total, 0, ',', '.') }}</td>
|
||||||
<td>
|
<td>
|
||||||
@if ($item->bukti1)
|
@if ($item->bukti1)
|
||||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank">
|
<a href="{{ NextCloudHelper::getNextcloudFile($item->bukti1) }}" target="_blank">
|
||||||
Download
|
Download
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
|
|||||||
Reference in New Issue
Block a user