php - symfony amazon S3 database -


i have project in symfony 2.6 i=use amazon s3 service , photo upload in server amazon. dump url photo this: https://s3-eu-west-1.amazonaws.com/aog-db-files-stage//2015/05/29/55688589ecdb4.jpg , question how write url in database , read photo template ?

entity photo

 class photo {     /**      * @orm\id      * @orm\column(type="integer")      * @orm\generatedvalue(strategy="auto")      */     private $id; /**  * @orm\column(type="string")  */ private $title;  /**  * @gedmo\timestampable(on="create")  * @orm\column(type="datetime", name="createdat")  */ protected $createdat;  /**  * @orm\column(name="photo_storage")  * @assert\file( maxsize="20m")  */ private $photo; 

and have formtype entity

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('title')         ->add('photo', 'file', array(             'label' => 'photo',         ))         ->getform(); }  public function setdefaultoptions(optionsresolverinterface $resolver) {     $resolver->setdefaults(array(         'data_class' => 'appbundle\entity\photo',     )); }  public function getname() {     return 'photo'; } 

and controller

    public function addaction(request $request) {     $em = $this->getdoctrine()->getmanager();      $post = new photo();      $form = $this->createform(new addphototype(), array());       if ($request->ismethod('post')) {         $form->bind($request);         if ($form->isvalid()) {             $data = $form->getdata();             $url = sprintf(                 '%s/%s',                 $this->container->getparameter('acme_storage.amazon_s3.base_url'),                 $this->getphotouploader()->upload($data['photo'])             );              dump($url);             $em->persist($post);             $em->flush();              return $this->redirect($this->get('router')->generate('homepage'));         }     }      return array(         "form" => $form->createview(),     ); }  /**  * @return \storagebundle\upload\photouploader  */ protected function getphotouploader() {     return $this->get('acme_storage.photo_uploader'); } 

how upload photos in amazon s3 (this work) , set url local database ?


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -