| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Services;
- use Exception;
- use Illuminate\Support\Facades\Http;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Str;
- class PdfConverterClient
- {
- const CONVERTER_ADDRESS = 'http://pdf-converter:5000/convert';
- /**
- * @param string $filePath
- * @return void
- * @throws Exception
- */
- public static function convert(string $filePath): void
- {
- if(!file_exists($filePath)) {
- throw new Exception("File does not exist");
- }
- $response = Http::attach('file', file_get_contents($filePath), '123.xlsx')->post(self::CONVERTER_ADDRESS);
- if($response->successful()) {
- $newFilename = Str::replace('.xlsx', '.pdf', $filePath);
- file_put_contents($newFilename, $response->body());
- } else {
- Log::error($response->clientError());
- }
- }
- }
|