Issue #1197πŸ’¬ AnsweredOpened Jun 13, 2018by frantischek0 reactions

Asset upload with Laravel 5.5

Quick answerby artf

https://laravel.com/docs/5.6/filesystem#file-uploads

Read full answer below ↓

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]β€’ Sep 17, 2019

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features β€” save days of integration work.

Browse premium plugins β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.