Issue #1197Opened June 13, 2018by frantischek0 reactions

Asset upload with Laravel 5.5

Question

Hi, I'm using grapesjs - 0.14.15 on my server. Trying to upload images in two different ways:

        assetManager: {
            upload: '/uploadAsset',
            assets: [],
            uploadText: 'Ziehe Dateien hier her oder klicke hier.',
            autoAdd: true,
            addBtnText: 'ext. Bild',
            modalTitle: 'Bild auswählen',
            dropzone: true,
            openAssetsOnDrop: true,
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },

and with:

        assetManager: {
            upload: '/uploadAsset',
            assets: [],
            uploadText: 'Ziehe Dateien hier her oder klicke hier.',
            autoAdd: true,
            addBtnText: 'ext. Bild',
            modalTitle: 'Bild auswählen',
            dropzone: true,
            openAssetsOnDrop: true,
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            uploadFile: function (e) {
                var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
                var formData = new FormData();
                for (var i in files) {
                    formData.append('file-' + i, files[i]) //containing all the selected images from local
                }
                $.ajax({
                    url: '/uploadAsset',
                    type: 'POST',
                    data: formData,
                    contentType: false,
                    crossDomain: true,
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    dataType: 'json',
                    mimeType: "multipart/form-data",
                    processData: false,
                    success: function (result) {
                        var myJSON = [];
                        $.each(result['data'], function (key, value) {
                            myJSON[key] = value;
                        });
                        var images = myJSON;
                        editor.AssetManager.add(images); //adding images to asset
                    }
                });

            }
        }

In my PHP file I only want to return the files array using:

    public function uploadAsset(Request $request)
    {
        return $request;
    }

But it's allways empty. Please help - thank you. Regards Frantischek

Answers (2)

lock[bot]September 17, 20190 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.