首页 > 解决方案 > 使用 Guzzle 客户端 API 和 Ajax 在 laravel 中上传多个图像和视频

问题描述

这是我的控制器,它获取访问令牌并发送 URL 以及数据以调用 API 并将图像存储在那里,发送基本 URL 并使用 guzzle 客户端存储 API URL,然后将表单中的所有字段作为参数和发送它们,但在我的第二个微服务中,当我记录请求时,我没有得到任何内容。

public function storeImage(Request $request) {
    Log::info('In GalleryController->StoeImage()');
    $input = $request->all();
    try {
          Log::info('Calling GalleryController::getGalleryAccessToken()');
          $access_token = $this->getGalleryAccessToken();
          Log::info('Got the access token from ProfessionalCategoryController::getProfessionAccessToken(). Now creating Profession!');

            Log::info('GALLERY_MANAGEMENT_BASE_URL . GALLERY_STORE_IMAGE__URL: ' . Config::get('app.GALLERY_MANAGEMENT_BASE_URL') . Config::get('app.GALLERY_STORE_IMAGE__URL'));

            $http = new Client(); //GuzzleHttp\Client
            $response = $http->post(
                Config::get('app.GALLERY_MANAGEMENT_BASE_URL') . Config::get('app.GALLERY_STORE_IMAGE__URL'),
                [
                    'headers' => [
                        'Accept'     => 'application/json',
                        'Authorization' => 'Bearer ' . $access_token
                    ],
                    'form_params' => $request->all()
                ]
            );
            Log::info('Got the response from Store Image');
            $responseJson = json_decode($response->getBody()->getContents(), true);
            return response()->json($responseJson, 200);
       
    } catch (\Exception $e) {
        Log::info('There was some exception inProfessionalCategoryController->createProfession()');
        Log::info($e->getMessage());
        $response = [
            'success' => false,
            'data' => '' ,
            'message' => $e->getMessage()
        ];
    
        return response()->json($response, 500);
    }
}

标签: phpajaxlaravelapiguzzle

解决方案


推荐阅读