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' => 'body', 'contents' => json_encode([ 'id' => $fileId ]), 'headers' => [ 'Content-Type' => 'application/json' ] ], [ 'name' => 'document', 'contents' => fopen($file->getPathname(), 'r') ] ] ]); return response()->json([ 'file' => $file->getClientOriginalName(), 'id' => $fileId, 'path' => $path, ]); } /** * * @param string $id * * @return JsonResponse * * @throws BindingResolutionException */ public function get(string $id): JsonResponse { $success = rand(0, 1); if ($success == 1) { $text = <<json([ 'text' => $text, 'ready' => true ]); } return response()->json([ 'ready' => false ]); } }