file('file'); $time = time(); $fileName = $time . '-' . $file->getClientOriginalName(); $fileId = $time . pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); $path = Storage::putFileAs('files/', $file, $fileName); $guzzle = new Client(); /** @var \Psr\Http\Message\ResponseInterface $response */ $response = $guzzle->request('POST', 'http://ingest.sandd/ingest', [ 'multipart' => [ [ 'name' => 'id', 'contents' => $fileId, 'headers' => [ 'Content-Type' => 'application/json' ] ], [ 'name' => 'document', 'contents' => fopen($file->getPathname(), 'r') ] ] ]); return response()->json([ 'file' => $file->getClientOriginalName(), 'id' => $fileId, 'path' => $path, ]); } catch (BadResponseException $e) { return response()->json([ 'message' => $e->getMessage(), 'response' => $e->getResponse() ], 400); } } /** * */ public function convert(): JsonResponse { $mdFileContent = request()->input('content'); $tmpFileId = (string) Str::uuid(); Storage::disk('local')->put('tmp/' . $tmpFileId . '.md', $mdFileContent); $tmpMdFilePath = Storage::path('tmp/' . $tmpFileId . '.md'); $pandoc = new Process([ 'pandoc', '-f', 'markdown', '-t', 'odt', $tmpMdFilePath ]); $pandoc->start(); while ($pandoc->isRunning()) { // } $odtFileContent = $pandoc->getOutput(); Storage::disk('local')->put('tmp/' . $tmpFileId . '.odt', $odtFileContent); return response()->json([ 'path' => 'tmp/' . $tmpFileId . '.odt' ]); } /** * * @param string $path * @return mixed */ public function download(string $path) { return Storage::download($path); } }