0

我正在使用 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 Intervention 保存该图像。这是一些代码:

$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 图像以及如何保存?谢谢您的帮助!

4

1 回答 1

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';
}
于 2016-06-15T01:35:10.313 回答