Uploads an image to Sony's CDN and returns the URL.

Sony requires all images (profile images, community images, etc) to be set with this CDN URL.

@param string $purpose
@return string
487154
private function uploadImage(string $purpose, string $imageData) : string
    {
        $parameters = [
            [
                'name' => 'purpose',
                'contents' => $purpose,
            ],
            [
                'name' => 'file',
                'filename' => 'dummy_file_name',
                'contents' => $imageData,
                'headers' => [
                    'Content-Type' => 'image/jpeg'
                ]
            ],
            [
                'name' => 'mimeType',
                'contents' => 'image/jpeg',
            ]
        ];

        $response = $this->postMultiPart(sprintf(self::SATCHEL_ENDPOINT, $this->id()), $parameters);

        return $response->url;
    }
334347
private function createPathForUpload()
    {
        return sprintf(
            '%s://%s/%s.files',
            self::$streamWrapperProtocol,
            urlencode($this->databaseName),
            urlencode($this->bucketName)
        );
    }
575574
protected function sftpUploadFile(): FunctionsInterface
    {
        /* the directory structure on remote host must exist to SFTP */
        if ($this->get('_localFileSize') > 0) {
            $this->get('_sftp')->uploadFile($this->get('_remoteFilePath'), $this->get('_localCacheFilePath'));
        }

        return $this;
    }
885876
public function getProfilePictureAction()
    {
        $melisCoreAuth = $this->serviceLocator->get('MelisCoreAuth');
        $moduleSvc = $this->getServiceLocator()->get('ModulesService');
        $user = $melisCoreAuth->getIdentity();
        $imageDefault = $moduleSvc->getModulePath('MelisCore') . '/public/images/profile/default_picture.jpg';

        if (!empty($user) && !empty($user->usr_image)) {
            $image = $user->usr_image;
        } else {
            $image = file_get_contents($imageDefault);
        }

        $response = $this->getResponse();

        $response->setContent($image);
        $response->getHeaders()
            ->addHeaderLine('Content-Transfer-Encoding', 'binary')
            ->addHeaderLine('Content-Type', 'image/jpg');

        return $response;
    }
1135766
public function src()
    {
        $src = $this->thumbnail();

        if (!$src) {
            $src = $this->file();
        }

        return $this->createAbsoluteUrl($src);
    }
671231
public function uploadAction()
    {
        $request = $this
            ->requestStack
            ->getCurrentRequest();

        /**
         * @var UploadedFile $file
         */
        $file = $request
            ->files
            ->get($this->uploadFieldName);

        if (!($file instanceof UploadedFile)) {
            return new JsonResponse([
                'status' => 'ko',
                'response' => [
                    'message' => 'Image not found',
                ],
            ]);
        }

        try {
            $image = $this
                ->imageUploader
                ->uploadImage($file);

            $routes = $this
                ->router
                ->getRouteCollection();

            $response = [
                'status' => 'ok',
                'response' => [
                    'id' => $image->getId(),
                    'extension' => $image->getExtension(),
                    'routes' => [
                        'view' => $routes
                            ->get($this->viewImageRouteName)
                            ->getPath(),
                        'resize' => $routes
                            ->get($this->resizeImageRouteName)
                            ->getPath(),
                    ],
                ],
            ];
        } catch (Exception $exception) {
            $response = [
                'status' => 'ko',
                'response' => [
                    'message' => $exception->getMessage(),
                ],
            ];
        }

        return new JsonResponse($response);
    }
960043
public function getAvatar() : ? string
    {
        //$this->cdn
        $cdn = \Phalcon\DI::getDefault()->getCdn() . '/avatars/';
        $avatar = $cdn . 'nopicture.png';

        if (!empty($this->profile_image)) {
            $avatar = $cdn . $this->profile_image;
        } elseif (!empty($this->profile_remote_image)) {
            $avatar = $this->profile_remote_image;
        }

        return $avatar;
    }
554034
public function upload()
    {
        $filename = $this->getName(true);

        if ( ! is_readable($filename) ) {
            throw new FileExistException('Image file from disk is not readable');
        }

        try {
            $this->getSoapClient()->UploadImage(array(
                'image'    => base64_encode(file_get_contents($filename)) ,
                'filename' => basename($filename) ,
            ));

            return $this;
        } catch ( SoapException $e ) {
            throw new UploadException('Error while uploading the image' , $e);
        }
    }
1133024
protected function getUploadedImage()
    {
        if ($this->getMappingResultsForProperty()->hasErrors()) {
            return null;
        }
        $image = $this->getPropertyValue();
        if ($image instanceof Image) {
            return $image;
        }
        return $this->propertyMapper->convert($this->getValueAttribute(), Image::class);
    }
990902
protected function validateImagesStore()
    {
        if ($this->isError()) {
            return null;
        }

        $error = false;

        foreach (array('logo', 'favicon') as $field) {

            if ($this->getSubmitted("delete_$field")) {
                $this->setSubmitted("data.$field", '');
            }

            $file = $this->request->file($field);

            if (empty($file)) {
                continue;
            }

            $result = $this->file_transfer->upload($file, null, 'image/upload/store');

            if ($result !== true) {
                $error = true;
                $this->setError($field, (string) $result);
                continue;
            }

            $this->setSubmitted("data.$field", $this->file_transfer->getTransferred(true));
        }

        return empty($error);
    }
1000896
protected function getValidationSchemaUrl()
    {
        $profile = $this->getValidationProfile();
        if ($filename = $this->getJsonSchemaFileFromRegistry($profile)) {
            // known profile id in the registry
            return $this->convertValidationSchemaFilenameToUrl($filename);
        } elseif (Utils::isHttpSource($profile)) {
            // url
            return $profile;
        } elseif (file_exists($filename = $this->basePath.DIRECTORY_SEPARATOR.$profile)) {
            // relative path - prefixed with basePath
            return $this->convertValidationSchemaFilenameToUrl($filename);
        } else {
            // absolute path (or relative to current working directory)
            return $this->convertValidationSchemaFilenameToUrl($profile);
        }
    }
195091
public function uploadImageAction(Request $request): Response
    {
        if ($this->isValidCsrfToken($request)) {
            $data = new ImageAssetUploadData(
                $request->files->get(self::FILE_KEY),
                $request->request->get(self::LANGUAGE_CODE_KEY)
            );

            $errors = $this->validator->validate($data);
            if ($errors->count() === 0) {
                try {
                    $file = $data->getFile();

                    $content = $this->imageAssetMapper->createAsset(
                        $file->getClientOriginalName(),
                        new ImageValue([
                            'path' => $file->getRealPath(),
                            'fileSize' => $file->getSize(),
                            'fileName' => $file->getClientOriginalName(),
                            'alternativeText' => null,
                        ]),
                        $data->getLanguageCode()
                    );

                    return new JsonResponse([
                        'destinationContent' => [
                            'id' => $content->contentInfo->id,
                            'name' => $content->getName(),
                            'locationId' => $content->contentInfo->mainLocationId,
                        ],
                        'value' => $this->imageAssetMapper->getAssetValue($content),
                    ]);
                } catch (Exception $e) {
                    return $this->createGenericErrorResponse($e->getMessage());
                }
            } else {
                return $this->createInvalidInputResponse($errors);
            }
        }

        return $this->createInvalidCsrfResponse();
    }
754211
public function downloadGravatarImage($email)
    {
        try {
            $gravatarUrl = $this->generateGravatarUrl($email);

            $response = $this->httpClient->get($gravatarUrl);
            $avatarPath = $this->generateAvatarPath($response->getHeader('Content-Type'));

            $this->fileUploadService->storeImage($avatarPath, $response->getBody());

            return $avatarPath;
        } catch (\Exception $e) {
            // If Guzzle throws an error, then most likely because you're
            // developing CampaignChain offline. Hence, don't worry about the
            // error.
        }
    }
903923
public function objectUrl($path)
    {
        if (URL::isValidUrl($path)) {
            return $path;
        }

        if ($this->storage) {
            return $this->storage->url($path);
        }

        return Storage::disk(config('admin.upload.disk'))->url($path);
    }
32819
public function getPicUrl($file_id, $width = 0, $height = 0,$water=false, $crop = self::resize_rect_in,$blur=-1){
        $path=$this->config['base_path'].DIRECTORY_SEPARATOR.$file_id;
        return $this->config['cdn'].$path;
    }
727502
public function getUploadedFlyFile($serial)
    {
        $path = $this->getUserDirectoryHash() . '/';
        if (filter_var($serial, FILTER_VALIDATE_URL)) {
            // Getting the File instance of the file url.
            $fakeFile = $this->getSerializer()->unserializeFile($serial);

            // Filesystem hack check.
            if ($fakeFile->getFileSystemId() !== $this->getUploadFSid()) {
                throw new \common_exception_NotAcceptable(
                    'The uploaded file url contains a wrong filesystem id!' .
                    '(Expected: `' . $this->getUploadFSid() . '` Actual: `' . $fakeFile->getFileSystemId() . '`)'
                );
            }

            $path .= $fakeFile->getBasename();
        }
        else {
            $path .= $serial;
        }

        $realFile = $this->getUploadDir()->getFile($path);
        if ($realFile->exists()) {
            return $realFile;
        }

        return null;
    }
1158
public function getResponsiveImagesDirectoryUrl(): string
    {
        return url($this->getBaseMediaDirectoryUrl().'/'.$this->pathGenerator->getPathForResponsiveImages($this->media)).'/';
    }