Prepare for each file.

@param UploadedFile $image

@return mixed|string
541366
protected function prepareForeach(UploadedFile $image = null)
    {
        $self       = clone $this;
        $self->name = $self->getStoreName($image);

        $self->callInterventionMethods($image->getRealPath());

        return tap($self->upload($image), function () use ($self) {
            $self->name = null;
        });
    }
867555
protected function getUploadedFilename(UploadedFile $file): string
    {
        $extension = $file->getClientOriginalExtension();

        return \sprintf('%s.%s', Str::random(10), $extension);
    }
76616
protected function resolveTempFileName(UploadedFile $file)
    {
        $name      = $file->getClientOriginalName();
        $extension = File::extension($name);
        $subdir    = sha1(time());
        $directory = storage_path() . '/app/uploads/' . $subdir;
        $filename  = sha1(time() . time()) . ".{$extension}";
        return ['directory' => $directory, 'subdir' => $subdir, 'filename' => $filename];
    }
885256
private function uploadFile(UploadedFile $file)
    {
        /** @var FileStorage $fileStorage */
        $fileStorage = Yii::$app->get('fileStorage');

        $filename = $fileStorage->saveUploadedFile($file);

        return $fileStorage->put($filename, $file->name);
    }
1294252
public function prepare($image)
    {
        if (request()->has(static::FILE_DELETE_FLAG)) {
            return $this->destroy();
        }

        $this->name = $this->getStoreName($image);

        $this->callInterventionMethods($image->getRealPath());

        return $this->uploadAndDeleteOriginal($image);
    }
706170
protected function createUploadedFile($file)
	{
		try {
			$imageManager = new ImageManager;
			$image = $imageManager->make($file);
			$extension = $this->getExtensionFromMime($image->mime());
			$fileName = $this->generateFileName($extension);
			$temporaryPath = $this->getTemporaryImageBasePath();
			$this->temporaryImage = $temporaryPath.'/'.$fileName;
			$image->save($this->temporaryImage);

			return new UploadedFile(
				$this->temporaryImage,
				$fileName, 
				$image->mime(),
				$image->filesize(),
				null,
				TRUE
			);
		} catch (Exception $e) {
			throw new ImageUploaderException("Error create uploaded file");
		}
	}
1015881
protected function prepareForeach(UploadedFile $file = null)
    {
        $self       = clone $this;
        $self->name = $self->getStoreName($file);

        return tap($self->upload($file), function () use ($self) {
            $self->name = null;
        });
    }
1136075
public function prepare(File $file, $entity, $field, $noclobber = true, $forceFilename = '')
    {
        $dir = $this->getDir($entity, $field);
        if ($forceFilename) {
            $pathname = $dir . '/' . $forceFilename;
        } else {
            if ($file instanceof UploadedFile) {
                $fileName = $file->getClientOriginalName();
            } else {
                $fileName = $file->getBasename();
            }

            $i = 0;
            do {
                $f = $this->namingStrategy->normalize($fileName, $i++);
                $pathname = $dir . '/' . $f;
            } while ($noclobber && $this->fs->exists($pathname));
            $this->fs->mkdir(dirname($pathname), 0777 & ~umask(), true);
            $this->fs->touch($pathname);
        }
        $this->preparedPaths[]= $pathname;
        return $pathname;
    }
985616
private static function parseUploadedFiles(array $uploadedFiles) {
        $parsed = array();

        foreach ($uploadedFiles as $field => $uploadedFile) {
            if (!isset($uploadedFile['error'])) {
                if (is_array($uploadedFile)) {
                    $parsed[$field] = static::parseUploadedFiles($uploadedFile);
                }
                continue;
            }
            $parsed[$field] = array();

            if (!is_array($uploadedFile['error'])) {
                $parsed[$field] = new static(
                        $uploadedFile['tmp_name'], isset($uploadedFile['name']) ? $uploadedFile['name'] : null, isset($uploadedFile['type']) ? $uploadedFile['type'] : null, isset($uploadedFile['size']) ? $uploadedFile['size'] : null, $uploadedFile['error'], true
                );
            } else {
                foreach ($uploadedFile['error'] as $fileIdx => $error) {
                    $parsed[$field][] = new static(
                            $uploadedFile['tmp_name'][$fileIdx], isset($uploadedFile['name']) ? $uploadedFile['name'][$fileIdx] : null, isset($uploadedFile['type']) ? $uploadedFile['type'][$fileIdx] : null, isset($uploadedFile['size']) ? $uploadedFile['size'][$fileIdx] : null, $uploadedFile['error'][$fileIdx], true
                    );
                }
            }
        }

        return $parsed;
    }
803857
protected function prepareForeach(UploadedFile $file = null)
    {
        $this->name = $this->getStoreName($file);

        return tap($this->upload($file), function () {
            $this->name = null;
        });
    }
457680
public function resize(UploadedFile $file, $style)
    {
        $quality = $this->option('quality', 90);

        $this->imagine = new $this->image_processor;

        $file_path = @tempnam(sys_get_temp_dir(), 'STP') . '.' . $file->getClientOriginalName();
        list($width, $height, $option, $enlarge) = $this->parseStyleDimensions($style);
        $method = 'resize' . ucfirst($option);

        if ($method == 'resizeCustom') {
            $this->resizeCustom($file, $style, $enlarge)
                ->save($file_path, [
                    'quality' => $quality,
                ]);

            return $file_path;
        }

        $image = $this->imagine->open($file->getRealPath());

        // Orient the file programmatically
        if ($this->option('auto_orient', false)) {
            $image = $this->autoOrient($file->getRealPath(), $image);
        }

        // Force a color palette
        if ($palette = $this->option('color_palette')) {
            $image->usePalette(new $palette);
        }

        $this->$method($image, $width, $height, $enlarge)
            ->save($file_path, [
                'quality' => $quality,
                'flatten' => false,
            ]);

        return $file_path;
    }
500523
protected function resolveType(UploadedFile $file)
    {
        $extension = $file->clientExtension() ?: $file->extension();

        foreach ($this->knownExtensions() as $type => $extensions) {
            if (in_array($extension, $extensions)) {
                return ends_with($type, 's') ? substr($type, 0, -1) : $type;
            }
        }

        return 'file';
    }
627483
public function createFrom($image)
    {
        $type           = pathinfo($image, PATHINFO_EXTENSION);
        $type           = ($type === 'jpg') ? 'jpeg' : $type;
        $createFrom     = 'ImageCreateFrom' . $type;

        return $createFrom($image);
    }
1064552
public function uploadImage(UploadedFile $file)
    {
        $image = $this
            ->imageManager
            ->createImage($file);

        $this
            ->mediaEventDispatcher
            ->dispatchImagePreUploadEvent($image);

        $this->imageObjectManager->persist($image);
        $this->imageObjectManager->flush($image);

        $this->fileManager->uploadFile(
            $image,
            file_get_contents($file->getRealPath()),
            true
        );

        $this
            ->mediaEventDispatcher
            ->dispatchImageOnUploadEvent($image);

        return $image;
    }
1093540
public function generateFileExtension(UploadedFile $uploadedFile)
    {
        // Retrieve original file name
        $filePath = $uploadedFile->getClientOriginalName();

        // Parse URL
        $fileInfo = pathinfo($filePath);

        // Return extension is available
        if (! empty($fileInfo['extension'])) {
            return strtolower($fileInfo['extension']);
        }

        throw ( new AssetsBadRequestException('Cannot detect file extension, provide it before uploading.') )->setStatusCode(400);
    }
1250402
private function getFile(Image $image)
    {
        $file = $image->getFile();

        if ($file instanceof \SplFileInfo) {
            return $file;
        }

        $url = $image->getUrl();

        if (null !== $url) {
            return new File($this->downloadFile($url));
        }

        return null;
    }
490643
public function setFileUpload(UploadedFile $file = null)
    {
        $propertyName = $this->getFileUploadPropertyName(__FUNCTION__);

        unset($this->fileUploads[$propertyName]);
        if ($file instanceof UploadedFile) {
            $this->fileUploads[$propertyName] = $file;
        }
    }