使用 ng-file-upload 从 ng-camera 上传图像以进行干预

Upload image from ng-camera with ng-file-upload to intervention

我正在使用 danialfarid/ng-file-upload 和 bcabanes/ng-camera。这是我的代码(咖啡):

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());

不知道能不能用Request::file("file"),因为是ng-camara拍的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 图像以及如何保存它?感谢您的帮助!

嗯,我是这样理解的: (咖啡)

$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'
        )

我用一个按钮调用函数 (jade):

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';
}