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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user