コード例 #1
0
 public function get(RootFile $file)
 {
     try {
         $api = new Api();
         $result = $api->resource(sprintf('%s/%s', $file->getUploaderPath(), $file->getBasename('.' . $file->getExtension())));
         $file->setType($result['resource_type'] === 'image' ? 'image' : 'file');
         if ($result['resource_type'] === 'image') {
             $config = $this->uploaderConfig->get('thumbnails');
             $edition = new Edition("thumbnail", null, $file->getUploaderPath(), ['type' => 'image', 'height' => $config['height'], 'width' => $config['width'], 'crop' => $config['crop'], 'cloudinary_response' => $result], true);
             $edition->setUrl($this->resolveUrl($edition));
             $file->addEdition($edition);
         }
         return $file;
     } catch (Api\NotFound $e) {
         return ['error' => 'S0001'];
     }
 }
コード例 #2
0
 public function get(RootFile $file)
 {
     if (!file_exists($file->getPathname())) {
         return ['error' => 'S0001'];
     }
     if ($file->isImage()) {
         $thumbName = $file->generateEditionFilename("thumbnail");
         $thumbPath = sprintf('%s/%s', $file->getPath(), $thumbName);
         if (!file_exists($thumbPath)) {
             return ['error' => 'S0002'];
         }
         $edition = new Edition("thumbnail", $thumbPath, $file->getUploaderPath(), ['type' => 'image'], true);
         $edition->setUrl($this->resolveUrl($edition));
         $file->addEdition($edition);
     }
     return $file;
 }
コード例 #3
0
 public function session($input)
 {
     $this->mergeConfig($input);
     $session = $input['optimus_uploader_files'];
     if ($session === null) {
         return [];
     }
     $return = [];
     foreach ($session as $file) {
         $fileObj = new RootFile($this->uploaderPath('/' . $file));
         $uploaderPath = str_replace('/' . $fileObj->getFilename(), '', $file);
         $fileObj->setUploaderPath($uploaderPath);
         $storage = $this->storage->get($fileObj);
         $id = \uniqid();
         if (is_array($storage) && isset($storage['error'])) {
             $return[] = array_merge(['uuid' => $id, 'name' => $fileObj->getFilename(), 'upload_path' => $file, 'type' => 'error', 'error_code' => $storage['error']], $storage);
         } else {
             $return[] = ['name' => $storage->getFilename(), 'upload_path' => sprintf('%s/%s', $storage->getUploaderPath(), $storage->getFilename()), 'file_type' => $storage->getType(), 'type' => 'session', 'thumbnailUrl' => $storage->getEdition('thumbnail')->getUrl(), 'uuid' => $id];
         }
     }
     return $return;
 }