Fix upload image endpoint
This commit is contained in:
parent
95b5cabc00
commit
c421290635
|
@ -42,6 +42,8 @@ trait ConsumesExternalService
|
||||||
$headers['Authorization'] = $this->key;
|
$headers['Authorization'] = $this->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$headers['Content-Type'] = 'multipart/form-data';
|
||||||
|
|
||||||
$client = new Client([
|
$client = new Client([
|
||||||
'base_uri' => $this->baseUri,
|
'base_uri' => $this->baseUri,
|
||||||
'headers' => $headers
|
'headers' => $headers
|
||||||
|
@ -57,22 +59,33 @@ trait ConsumesExternalService
|
||||||
{
|
{
|
||||||
$multipart = [];
|
$multipart = [];
|
||||||
foreach ($body as $key => $value) {
|
foreach ($body as $key => $value) {
|
||||||
if ($value instanceof UploadedFile) {
|
if(is_array($value)){
|
||||||
array_push($multipart, [
|
foreach ($value as $v){
|
||||||
'name' => $key,
|
array_push($multipart, $this->convertToMultiFormArray($key.'[]',$v));
|
||||||
'contents' => file_get_contents($value->getRealPath()),
|
}
|
||||||
'mine-type' => $value->getMimeType(),
|
}else{
|
||||||
'filename' => $value->getClientOriginalName(),
|
array_push($multipart, $this->convertToMultiFormArray($key,$value));
|
||||||
// 'headers' => [ 'Content-type' => 'application/octet-stream']
|
|
||||||
// 'Content-type' => 'multipart/form-data',
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
array_push($multipart, [
|
|
||||||
'name' => $key,
|
|
||||||
'contents' => $value,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $multipart;
|
return $multipart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function convertToMultiFormArray($key , $value): array
|
||||||
|
{
|
||||||
|
if ($value instanceof UploadedFile) {
|
||||||
|
return [
|
||||||
|
'name' => $key,
|
||||||
|
'contents' => file_get_contents($value->getRealPath()),
|
||||||
|
'mine-type' => $value->getMimeType(),
|
||||||
|
'filename' => $value->getClientOriginalName(),
|
||||||
|
// 'headers' => [ 'Content-type' => 'application/octet-stream']
|
||||||
|
// 'Content-type' => 'multipart/form-data',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return[
|
||||||
|
'name' => $key,
|
||||||
|
'contents' => $value,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,16 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2.5",
|
"php": "^7.3|^8.0",
|
||||||
"dusterio/lumen-passport": "^0.2.18",
|
"dusterio/lumen-passport": "^0.3.0",
|
||||||
"guzzlehttp/guzzle": "^6.5",
|
"guzzlehttp/guzzle": "^7.3",
|
||||||
"laravel/lumen-framework": "^7.0"
|
"laravel/lumen-framework": "^8.0",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fzaninotto/faker": "^1.9.1",
|
"fzaninotto/faker": "^1.9.1",
|
||||||
"mockery/mockery": "^1.3.1",
|
"mockery/mockery": "^1.3.1",
|
||||||
"phpunit/phpunit": "^8.5"
|
"phpunit/phpunit": "^9.5"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": [
|
"classmap": [
|
||||||
|
@ -21,7 +22,9 @@
|
||||||
"database/factories"
|
"database/factories"
|
||||||
],
|
],
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/"
|
"App\\": "app/",
|
||||||
|
"Database\\Factories\\": "database/factories/",
|
||||||
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue