2016-05-16 67 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'; 
}