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