英文:
How to send saved file to external API in Laravel?
问题
以下是您要翻译的内容:
我正在构建一个NextJS网站应用,用户需要通过上传国民身份证来完成他的个人资料。我使用Laravel保存了上传的文件。一切都正常,直到保存部分。但当我尝试将已保存的文件发送到外部API时,API会抛出一个错误,要求我“发送有效的图像”。外部API接受JPG、JPEG和PDF格式。
这是我的代码:
$pan = Storage::get(auth()->user()->pan_photo);
$data = ['pancard' => $pan,];
$response = Http::asForm()
->withHeaders([
'一些自定义标头'
])->put('https://staging.eko.in:25004/ekoapi/v1/user/service/activate', $data);
Log::channel('response')->info($response);
我在这里做错了吗?
英文:
I'm building a NextJS webapp in which a user is supposed to complete his profile by uploading his national ID. I'm saving the uploaded file using Laravel. Everything works fine till the saving part. But when I'm trying to send the saved to file to an external API, the API throws me an error asking me to Send a valid image
. The external API accepts, JPG, JPEG and PDF.
Here's my code:
$pan = Storage::get(auth()->user()->pan_photo);
$data = ['pancard' => $pan,];
$response = Http::asForm()
->withHeaders([
'some custom headers'
])->put('https://staging.eko.in:25004/ekoapi/v1/user/service/activate', $data);
Log::channel('response')->info($response);
Am I doing something wrong here?
答案1
得分: 0
你需要在这里使用 POST
,PUT/PATCH
不会起作用,因为这是PHP的限制,所以不要使用 put
函数,改成 post
。
<?php
Http::asForm()->post('你的网址在这里', $data);
英文:
You have to use POST
here, A PUT/PATCH
will not work as this is a limitation of the PHP, So instead of using put
function you need to change it to post
<?php
Http::asForm()->post('Your url here', $data);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论