【发布时间】:2020-11-13 12:56:38
【问题描述】:
有什么方法可以使用 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>
我不断收到Call to a member function path() on null
我想要做的是获取文件上传,将其上传到 Imgur 并获取 URL 以将其插入到我的数据库中。
【问题讨论】:
-
您是否尝试在代码中使用一些
dumps?如果你转储$request->file('thumbnail')怎么办? -
谢谢。我刚刚检查了我的刀片文件。我在请求中使用了“文件”而不是“缩略图”。现在如何从响应中获取 URL?
-
Guzzle 请求的响应是什么?你能试试
dump(json_decode($response->getBody()->getContents(), true)); -
另一个错误。
GuzzleHttp\Exception\ClientException Client error:POST api.imgur.com/3/image` 导致403 Permission Denied响应:{"data":{"error":"Malformed auth header","request":"\/3\/image","method":" POST"},"success":false,"status":403}` 我正在使用标头进行身份验证。 -
我已经对标题错位的问题进行了排序
标签: php laravel image upload imgur