app/Http/Controllers/Api/CamerasController.php
// public function uploadvideo(Request $request, ImageUploadHandler $uploader) {
public function uploadvideo(Request $request, ImageUploadHandler $uploader) {
public function uploadvideo ( Request $request ImageUploadHandler $uploader ) {
public function uploadvideo(Request $request) {
        $ret = $this->Camera_Check($request);
        $err = $ret['err'];
        $user_id = $ret['user_id'];
        $camera = $ret['camera'];
        if ($err == 0) {
            $camera_id = $camera->id;
            if (isset($request->RequestID)) {
                $query = array(
                    'id' => $request->RequestID,
                    'camera_id' => $camera_id,
                    'action' => 'UV',
                    'status' => ACTION_REQUESTED,
                );
                $actions = DB::table('actions')->where($query);
                $action  = $actions->first();
                if ($action) {
                    $query = array(
                        'id' => $action->photo_id,
                        'camera_id' => $camera_id,
                    );
                    $photos = DB::table('photos')->where($query);
                    $photo = $photos->first();
                    if ($photo) {
                        if (isset($request->blockid)) {
                            $ret =$this->uploadblock_merge('uploadvideo', $camera, $photo->id, $request->blockid, $request->crc32);
                            $err = $ret['err'];
                        } else {
                            $file = $request->Image;
                            if ($file && $file->isValid()) {
                                $uploader = new ImageUploadHandler;
                                if (env('APP_STORAGE') == 'AWS_S3') { 
                                    $ret = $uploader->s3_save_file($file, $photo->id);
                                } else if (env('APP_STORAGE') == 'ALI_OSS') {
                                    $ret = $uploader->oss_save_file($file, $photo->id);
                                } else {
                                    $ret = $uploader->save_file($camera_id, $file);
                                }
                                $err = $ret['err'];
                            } else {
                                $err = ERR_NO_UPLOAD_FILE;
                            }
                        }
                    } else {
                        $err = ERR_INVALID_PHOTO_ID;
                    }
                } else {
                    $err = ERR_INVALID_REQUEST_ID;
                }
            } else {
                $err = ERR_NO_REQUEST_ID;
            }
            if ($err == 0) {
                $filesize = $ret['filesize'];
                $imagename = $ret['imagename'];
                $savename = $ret['savename'];
                $param = $request;
                $param['camera_id'] = $camera_id;
                $param['filename'] = $request->FileName;
                $param['filesize'] = $filesize; 
                $param['imagename'] = $imagename; 
                $points = $this->Plan_Update($param, 1);
                $param['points'] = $points;
                $data = [];
                $data['action'] = 0;
                $data['uploadtype'] = 4; 
                $data['resolution'] = $request->upload_resolution;
                $data['imagename'] = $ret['imagename'];
                if ((env('APP_STORAGE') == 'AWS_S3') || (env('APP_STORAGE') == 'ALI_OSS')) { 
                } else {
                    $data['original_name'] = $savename; 
                }
                $data['filesize'] = $filesize;
                $data['points'] = $points;
                $photos->update($data);
                $this->Camera_Status_Update($user_id, $param, 'upload_video', 1);
                $data = [];
                $data['status'] = ACTION_COMPLETED;
                $data['completed'] = $this->_datetime_get($camera);
                $data['photo_cnt'] = 1;
                $actions->update($data);
                $this->email_Photo_Send($user_id, $camera, $savename);
            }
        }
        $response = $this->Response_Result($err, $camera);
        if ($err == 0) {
            if ($user_id && $camera) {
                $body = 'New Video: '.$request->FileName;
                $this->pushNewFile($user_id, $camera, $body);
                $this->LogApi_Add('uploadvideo', 1, $user_id, $camera->id, $request, $response);
            }
        } else if ($err == ERR_CRC32_FAIL) {
            $response['CRC32'] = $ret['CRC32'];
        }
        return $response;
    }
public function uploadvideo ( Request $ request ) { $ ret = $ this -> Camera_Check ( $ request ) ; $ err = $ ret [ 'err' ] ; $ user_id = $ ret [ 'user_id' ] ; $ camera = $ ret [ 'camera' ] ; if ( $ err == 0 ) { $ camera_id = $ camera -> id ; if ( isset ( $ request -> RequestID ) ) { $ query = array ( 'id' => $ request -> RequestID , 'camera_id' => $ camera_id , 'action' => 'UV' , 'status' => ACTION_REQUESTED , ) ; $ actions = DB :: table ( 'actions' ) -> where ( $ query ) ; $ action = $ actions -> first ( ) ; if ( $ action ) { $ query = array ( 'id' => $ action -> photo_id , 'camera_id' => $ camera_id , ) ; $ photos = DB :: table ( 'photos' ) -> where ( $ query ) ; $ photo = $ photos -> first ( ) ; if ( $ photo ) { if ( isset ( $ request -> blockid ) ) { $ ret = $ this -> uploadblock_merge ( 'uploadvideo' , $ camera , $ photo -> id , $ request -> blockid , $ request -> crc32 ) ; $ err = $ ret [ 'err' ] ; } else { $ file = $ request -> Image ; if ( $ file && $ file -> isValid ( ) ) { $ uploader = new ImageUploadHandler ; if ( env ( 'APP_STORAGE' ) == 'AWS_S3' ) { $ ret = $ uploader -> s3_save_file ( $ file , $ photo -> id ) ; } else if ( env ( 'APP_STORAGE' ) == 'ALI_OSS' ) { $ ret = $ uploader -> oss_save_file ( $ file , $ photo -> id ) ; } else { $ ret = $ uploader -> save_file ( $ camera_id , $ file ) ; } $ err = $ ret [ 'err' ] ; } else { $ err = ERR_NO_UPLOAD_FILE ; } } } else { $ err = ERR_INVALID_PHOTO_ID ; } } else { $ err = ERR_INVALID_REQUEST_ID ; } } else { $ err = ERR_NO_REQUEST_ID ; } if ( $ err == 0 ) { $ filesize = $ ret [ 'filesize' ] ; $ imagename = $ ret [ 'imagename' ] ; $ savename = $ ret [ 'savename' ] ; $ param = $ request ; $ param [ 'camera_id' ] = $ camera_id ; $ param [ 'filename' ] = $ request -> FileName ; $ param [ 'filesize' ] = $ filesize ; $ param [ 'imagename' ] = $ imagename ; $ points = $ this -> Plan_Update ( $ param , 1 ) ; $ param [ 'points' ] = $ points ; $ data = [ ] ; $ data [ 'action' ] = 0 ; $ data [ 'uploadtype' ] = 4 ; $ data [ 'resolution' ] = $ request -> upload_resolution ; $ data [ 'imagename' ] = $ ret [ 'imagename' ] ; if ( ( env ( 'APP_STORAGE' ) == 'AWS_S3' ) || ( env ( 'APP_STORAGE' ) == 'ALI_OSS' ) ) { } else { $ data [ 'original_name' ] = $ savename ; } $ data [ 'filesize' ] = $ filesize ; $ data [ 'points' ] = $ points ; $ photos -> update ( $ data ) ; $ this -> Camera_Status_Update ( $ user_id , $ param , 'upload_video' , 1 ) ; $ data = [ ] ; $ data [ 'status' ] = ACTION_COMPLETED ; $ data [ 'completed' ] = $ this -> _datetime_get ( $ camera ) ; $ data [ 'photo_cnt' ] = 1 ; $ actions -> update ( $ data ) ; $ this -> email_Photo_Send ( $ user_id , $ camera , $ savename ) ; } } $ response = $ this -> Response_Result ( $ err , $ camera ) ; if ( $ err == 0 ) { if ( $ user_id && $ camera ) { $ body = 'New Video: ' . $ request -> FileName ; $ this -> pushNewFile ( $ user_id , $ camera , $ body ) ; $ this -> LogApi_Add ( 'uploadvideo' , 1 , $ user_id , $ camera -> id , $ request , $ response ) ; } } else if ( $ err == ERR_CRC32_FAIL ) { $ response [ 'CRC32' ] = $ ret [ 'CRC32' ] ; } return $ response ; }
public function uploadvideo(Request $request, ImageUploadHandler $uploader) {
public function uploadvideo ( Request $request ImageUploadHandler $uploader ) {
// $file = $request->Image; // $file = $request->file('Image'); // return dd($file); /* search Action */ /* search Photo */ // $ret =$this->uploadblock_merge('uploadvideo', $camera, $request->FileName, $request->blockid, $request->crc32); //if (env('S3_ENABLE')) { //$ret['filesize']; //$ret['imagename']; /* update Plan */ /* update Photo */ // 1:photo_thumb, 2:photo_original, 3:video_thumb, 4:video_original //$data['photo_compression'] = $request->photo_compression; //if (env('S3_ENABLE')) { // do nothing //$ret['savename']; /* update Camera Status */ /* update Action */ // $data['completed'] = date('Y-m-d H:i:s'); ////$crc32 = $ret['CRC32']; // $response = $this->Response_Result($err, $camera); // } else { // $response = $this->Response_Result($err, $camera); // for test // $response['imagename'] = $file->getClientOriginalName(); // PICT0001.JPG // $response['filesize'] = $file->getClientSize();          // 7032 //+