第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Laravel 將圖像上傳到 Imgur?

如何使用 Laravel 將圖像上傳到 Imgur?

PHP
慕尼黑8549860 2023-08-19 17:33:16
有什么方法可以使用 Laravel 將圖像上傳到 Imgur。我目前正在使用$client = new \GuzzleHttp\Client();$response = $client->request('POST', 'https://api.imgur.com/3/image', [    'headers' => [        'authorization' => 'Client-ID ' . 'app_id',        'content-type' => 'application/x-www-form-urlencoded',    ],    'form_params' => [        'image' => base64_encode(file_get_contents($request->file('thumbnail')))    ],]);return response()->json(json_decode(($response->getBody()->getContents())));我的刀片文件是<tr>    <td>Thumbnail</td>    <td>        <input type="file" name="file" id="file">    </td></tr>我繼續(xù)得到Call to a member function path() on null我想要做的是上傳文件,將其上傳到 Imgur 并獲取 URL 以將其插入到我的數(shù)據(jù)庫中。
查看完整描述

2 回答

?
開滿天機(jī)

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個贊

嘗試這個,


$file = $request->file('file');

        $file_path = $file->getPathName();

        $client = new \GuzzleHttp\Client();

        $response = $client->request('POST', 'https://api.imgur.com/3/image', [

            'headers' => [

                    'authorization' => 'Client-ID ' . 'your-client-id-here',

                    'content-type' => 'application/x-www-form-urlencoded',

                ],

            'form_params' => [

                    'image' => base64_encode(file_get_contents($request->file('file')->path($file_path)))

                ],

            ]);

        $data['file'] = data_get(response()->json(json_decode(($response->getBody()->getContents())))->getData(), 'data.link');


查看完整回答
反對 回復(fù) 2023-08-19
?
慕桂英3389331

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個贊

Laravel 9 及以上答案的更新,


        use Illuminate\Support\Facades\Http;


        $file = $request->file('file');

        $file_path = $file->getPathName();

        $response = Http::withHeaders([

            'authorization' => 'Client-ID ' . 'your-client-id-here',

            'content-type' => 'application/x-www-form-urlencoded',

        ])->send('POST', 'https://api.imgur.com/3/image', [

            'form_params' => [

                    'image' => base64_encode(file_get_contents($request->file('file')->path($file_path)))

                ],

            ]);

        $data['file'] = data_get(response()->json(json_decode(($response->getBody()->getContents())))->getData(), 'data.link');


不要使用 http Facadepost()方法將表單發(fā)送到 imgur,它會序列化表單數(shù)據(jù),服務(wù)器將收到 400 bad method 響應(yīng)。


查看完整回答
反對 回復(fù) 2023-08-19
  • 2 回答
  • 0 關(guān)注
  • 155 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號