新聞中心
這篇文章給大家介紹如何在Laravel中使用Gin接口調(diào)用formData上傳文件,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

第一次錯誤:
[output] 【c.FormFile error==>】 multipart: NextPart: EOF
file 沒有傳值,或者非預(yù)定格式,stream resource
第二次錯誤:
[output] 【c.FormFile error==>】 multipart: NextPart: bufio: buffer full
header頭不需要 content-type => 'multipart/form-data'
php 調(diào)用參考:
你可以通過使用 multipart 請求參數(shù)來發(fā)送表單 (表單 enctype 屬性需要設(shè)置 multipart/form-data ) 文件, 該參數(shù)接收一個包含多個關(guān)聯(lián)數(shù)組的數(shù)組,每個關(guān)聯(lián)數(shù)組包含一下鍵名:
name: (必須,字符串) 映射到表單字段的名稱。
contents: (必須,混合) 提供一個字符串,可以是 fopen 返回的資源、或者一個
Psr\Http\Message\StreamInterface 的實(shí)例。
$response = $client->request('POST', 'http://post', [
'multipart' => [
[
'name' => 'field_name',
'contents' => 'abc'
],
[
'name' => 'file_name',
'contents' => fopen('/path/to/file', 'r')
],
[
'name' => 'other_file',
'contents' => 'hello',
'filename' => 'filename.txt',
'headers' => [
'X-Foo' => 'this is an extra header to include'
]
]
]
]);ps:
multipart 格式如上,需要注意的是參數(shù)如果是數(shù)組,同樣需要重組,不重組就是第三個問題:Invalid resource type: array
修改參數(shù)格式為 json, 畢竟跨語言 json xml 才是王道
```
$response = $client->request('POST', 'http://post', [
'multipart' => [
[
'name' => 'field_name',
'contents' => json_encode(["abc", "abd"])
]
]
]
]);關(guān)于如何在Laravel中使用Gin接口調(diào)用formData上傳文件就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
當(dāng)前標(biāo)題:如何在Laravel中使用Gin接口調(diào)用formData上傳文件-創(chuàng)新互聯(lián)
文章URL:http://www.dlmjj.cn/article/gpcci.html


咨詢
建站咨詢
