protected function resolveAddAttachments(EntityModel $modelAttachment, array $actions, $contentId)
 {
     foreach ($actions as $uploadName) {
         $metaUploadName = $uploadName . '_meta';
         if (!isset($_POST[$metaUploadName]) || !is_array($_POST[$metaUploadName])) {
             throw new \Exception('Upload is missing meta inputs');
         }
         $meta = $_POST[$metaUploadName];
         $mime = $meta['mime'];
         $filename = $_POST[$uploadName . '_meta']['filename'];
         $thumbPrototypeB64 = $_POST[$uploadName . '_thumbPrototype'];
         $thumbPrototype = ImageBase64Upload::saveTmp($thumbPrototypeB64, 'thumbPrototype_' . $filename);
         $fullImageB64 = $_POST[$uploadName];
         //if headimage, use thumb prototype as full size image
         $fullImage = $mime == 'HEADIMAGE' ? ImageBase64Upload::saveTmp($thumbPrototypeB64, $filename) : ImageBase64Upload::saveTmp($fullImageB64, $filename);
         $row = ['contentId' => $contentId, 'file' => $fullImage];
         if ($mime == 'IMAGE') {
             $attachment = new ImageAttachment();
         } elseif ($mime == 'HEADIMAGE') {
             $attachment = new MainimageAttachment();
         } else {
             throw new \Exception('Unknown mime: ' . $mime);
         }
         $attachment->setRow(ArrayHash::from($row));
         $attachment->setThumbPrototypeFullPath($thumbPrototype->getFullTmpFilePath());
         $url = $attachment->create();
         $thumbPrototype->unlink();
         $attachmentData = ['contentId' => $contentId, 'mime' => $mime, 'title' => $filename, 'url' => $url];
         $modelAttachment->insert($attachmentData);
     }
 }
 protected function prepareAttachments($attachments)
 {
     $prepared = ['IMAGE' => [], 'HEADIMAGE' => [], 'VIDEO' => []];
     foreach ($attachments as $key => $attachment) {
         if ($attachment['mime'] == "IMAGE") {
             $image = new \Custom\Content\ImageAttachment();
             $image->setRow(ArrayHash::from($attachment));
             $image->run();
             $attachment['_data'] = $image;
         }
         if ($attachment['mime'] == "HEADIMAGE") {
             $image = new \Custom\Content\MainimageAttachment();
             $image->setRow(ArrayHash::from($attachment));
             $image->run();
             $attachment['_data'] = $image;
         }
         $mime = $attachment['mime'];
         $prepared[$attachment['mime']][] = $attachment;
     }
     return ArrayHash::from($prepared);
 }