error get public url
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Helpers;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class NextCloudHelper
|
||||
{
|
||||
@@ -102,19 +103,53 @@ class NextCloudHelper
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getFileUrl($filePath)
|
||||
{
|
||||
$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
|
||||
$relativePath = "/mktia/remote.php/dav/files/{$username}/" . ltrim($filePath, '/');
|
||||
// Build the full URL
|
||||
$url = rtrim($baseUrl, '/') . $relativePath . "?token={$publicToken}";
|
||||
|
||||
// Return the full accessible URL
|
||||
return rtrim($baseUrl, '/') . '/' . $relativePath;
|
||||
// Initialize cURL
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user in Nextcloud.
|
||||
*
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"laravel/tinker": "^2.9",
|
||||
"laravel/ui": "^4.6",
|
||||
"laravolt/avatar": "^6.0",
|
||||
"league/flysystem-webdav": "^3.29",
|
||||
"nino/laravel-nextcloud-fs": "^2.0",
|
||||
"phpoffice/phpspreadsheet": "^3.5",
|
||||
"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",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "83771e2a711327eac79ef3f7b30673da",
|
||||
"content-hash": "fc2177036b736100113a527777c8cbc8",
|
||||
"packages": [
|
||||
{
|
||||
"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>
|
||||
@if ($item->bukti1)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank">
|
||||
<a href="{{ NextCloudHelper::getNextcloudFile($item->bukti1) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
|
||||
Reference in New Issue
Block a user