我应该如何通过Guzzle客户端将文件发送到laravel中的api服务器

我应该如何通过Guzzle客户端将文件发送到laravel中的api服务器,api,file-upload,upload,guzzlehttp,Api,File Upload,Upload,Guzzlehttp,你能告诉我我应该如何发送一个文件上传到api上吗 在api服务器中,我们有一个post方法,它提供两个参数: 一个name在查询中,一个formData中,然后它给出一个链接作为响应主体。 我将通过guzzle客户端以以下格式发送文件: $file = $request->file('InputFile'); $file_path = $file->getPathname(); $response = $this->CX_Client->post('/file/uploa

你能告诉我我应该如何发送一个文件上传到api上吗

在api服务器中,我们有一个post方法,它提供两个参数: 一个
name
在查询中,一个
formData
中,然后它给出一个链接作为响应主体。 我将通过guzzle客户端以以下格式发送文件:

$file = $request->file('InputFile');
$file_path = $file->getPathname();
$response = $this->CX_Client->post('/file/upload?name='.$fileName, [
                'formData' =>
                [
                    'file' =>
                    [
                            'name'     => 'InputFile',
                            'contents' => fopen($file_path, 'r'),
                            'filename' => $fileName
                    ]

                ]
            ]);

但这不起作用,服务器无法在此请求中找到其参数。我怎么了?

你应该使用
multipart
而不是
formData


我将上传的文件保存到public->storage(使用artisan链接),然后尝试上传到服务器。 但是我无法获得fopen('/path/to/file',r')

正在尝试
'contents'=>fopen('/'.$filename,file\u get\u contents($image),'r')

但错误在于:

{message: "fopen(/1_1.jpeg): failed to open stream: No such file or directory",…}
exception: "ErrorException"
file: "/Users/marcellopato/Sites/primorossicontemplado/app/Http/Controllers/DocumentoController.php"
line: 234
message: "fopen(/1_1.jpeg): failed to open stream: No such file or directory"
trace: [{function: "handleError", class: "Illuminate\Foundation\Bootstrap\HandleExceptions", type: "->"},…]

我做错了什么

{message: "fopen(/1_1.jpeg): failed to open stream: No such file or directory",…}
exception: "ErrorException"
file: "/Users/marcellopato/Sites/primorossicontemplado/app/Http/Controllers/DocumentoController.php"
line: 234
message: "fopen(/1_1.jpeg): failed to open stream: No such file or directory"
trace: [{function: "handleError", class: "Illuminate\Foundation\Bootstrap\HandleExceptions", type: "->"},…]