2016-05-16 71 views
0

我使用danialfarid/ng-file-upload和bcabanes/ng-camera。這是我的代碼(咖啡):從ng-file-upload上載ng-file-upload到干預圖像

file = $scope.vm.picture 
if (file) 

    Upload.upload({ 
     url: "::imagenes/store", 
     fields: {'Title': "test"}, 
     file: file, 
     headers: { 
      'Accept': 'application/json;odata=verbose', 'content-type': 'image/jpeg', 'X-RequestDigest': $("#__REQUESTDIGEST").val() 
     } 
    }).success((data, status, headers)-> 
     console.log('Complete!'); 
    ); 

我的導航顯示(慢)的數據進行發送,但我不知道如何保存與Laravel干預的形象。下面是一些代碼:

$file = Request::file("file"); 
$info = explode(".", $file->getClientOriginalName()); 

我不知道我是否可以使用支持::文件(「文件」),因爲它是由NG-卡馬拉採取一個base64形象:

    ng-camera(
         capture-message="Sonrie!" 
         output-height="320" 
         output-width="426" 
         crop-height="320" 
         crop-width="426" 
         image-format="jpeg" 
         jpeg-quality="100" 
         action-message="Tomar foto" 
         snapshot="vm.picture" 
         flash-fallback-url="/images/webcam.swf" 
         shutter-url="/sounds/shutter.mp3" 
         style="display: inline-block") 

怎麼辦我發送base64圖像,如何保存它?感謝您的幫助!

回答

0

好吧,我得到這樣的: (咖啡)

$scope.upload =()-> 
    file = $scope.vm.picture 

    if (file) 

     file = file.replace(/^data\:image\/\w+\;base64\,/, '') 

     $http.post('imagenes/store', {foto: file, paciente_id: $scope.paciente.id}).then((r)-> 
      toastr.success 'Uploaded correctly.' 
     , (r2)-> 
      toastr.error 'Uploaded error', 'Error' 
     ) 

我把一個按鈕的功能(玉):

md-button.md-raised(ng-show="vm.picture" type="button" ng-click="upload()") Save 

在Laravel:

public function postStore() 
{ 
    $folder = 'images/perfil/'; 

    if (Request::has('foto')) { 
     $folder = 'images/perfil/'; 
     File::makeDirectory($folder, $mode = 0777, true, true); 

     // THIS IS THE IMPORTANT!!! ------------ 
     $file = Request::input("foto"); 
     $binary_data = base64_decode($file); 
     $result = file_put_contents($folder .'/aName.jpg', $binary_data); 
     // ------------------------------------- 

     $img = Image::make($folder . '/aName.jpg'); 
     $img->fit(300); 
     $img->save(); 
    } 

    return 'Saved'; 
}