Craft\EmbeddedAssetsService::_storeFile PHP Method

_storeFile() private method

private _storeFile ( EmbeddedAssetsModel $media, $folderId )
$media EmbeddedAssetsModel
    private function _storeFile(EmbeddedAssetsModel $media, $folderId)
    {
        $fileLabel = substr(preg_replace('/[^a-z0-9]+/i', '-', $media->getTitle()), 0, 40);
        $filePrefix = EmbeddedAssetsPlugin::getFileNamePrefix();
        $fileExtension = '.json';
        $fileName = $filePrefix . $fileLabel . $fileExtension;
        $existingFile = craft()->assets->findFile(array('folderId' => $folderId, 'filename' => $fileName));
        if ($existingFile) {
            EmbeddedAssetsPlugin::log("File with name \"{$fileName}\" already exists in this location");
            $fileUniqueId = DateTimeHelper::currentUTCDateTime()->format('ymd_His');
            $fileName = $filePrefix . $fileLabel . '_' . $fileUniqueId . $fileExtension;
        }
        $fileData = $media->getAttributes(null, true);
        $fileData['__embeddedasset__'] = true;
        unset($fileData['id']);
        unset($fileData['settings']);
        $this->_addToFiles('assets-upload', $fileName, JsonHelper::encode($fileData), 'application/json');
        $response = craft()->assets->uploadFile($folderId);
        if ($response->isSuccess()) {
            $fileId = $response->getDataItem('fileId');
            $file = craft()->assets->getFileById($fileId);
            return $file;
        } else {
            throw new \Exception($response->errorMessage);
        }
    }