diff --git a/src/Http/RequestTransformer.php b/src/Http/RequestTransformer.php index d2b50a75806..42396b75606 100644 --- a/src/Http/RequestTransformer.php +++ b/src/Http/RequestTransformer.php @@ -134,11 +134,17 @@ protected static function convertFiles($data, $files, $path = '') */ protected static function convertFile($file) { + $error = $file->getError(); + $tmpName = ''; + if ($error === UPLOAD_ERR_OK) { + $tmpName = $file->getStream()->getMetadata('uri'); + } + return [ 'name' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), - 'tmp_name' => $file->getStream()->getMetadata('uri'), - 'error' => $file->getError(), + 'tmp_name' => $tmpName, + 'error' => $error, 'size' => $file->getSize(), ]; } diff --git a/tests/TestCase/Http/RequestTransformerTest.php b/tests/TestCase/Http/RequestTransformerTest.php index 0a1a1f10a7c..968b29680c5 100644 --- a/tests/TestCase/Http/RequestTransformerTest.php +++ b/tests/TestCase/Http/RequestTransformerTest.php @@ -147,6 +147,13 @@ public function testToCakeParamsPopulated() public function testToCakeUploadedFiles() { $files = [ + 'no_file' => [ + 'name' => ['file' => ''], + 'type' => ['file' => ''], + 'tmp_name' => ['file' => ''], + 'error' => ['file' => UPLOAD_ERR_NO_FILE], + 'size' => ['file' => 0] + ], 'image_main' => [ 'name' => ['file' => 'born on.txt'], 'type' => ['file' => 'text/plain'], @@ -205,6 +212,15 @@ public function testToCakeUploadedFiles() 'size' => 17178, ] ], + 'no_file' => [ + 'file' => [ + 'name' => '', + 'type' => '', + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'size' => 0, + ] + ], 'pictures' => [ 0 => [ 'name' => 'A cat',