mardi 26 avril 2022

Upload image to S3 from Tinymce using Laravel 5

I'm trying to upload an image using Tinymce to S3. Original file size is 151kb but on S3 it only goes up 24 bytes. I checked the size of the file that comes from the request to the controller and it is 151kb. Why is it only uploading 24 bytes?

This is my controller

public function upload(Request $request)
    {
        $fileName=$request->file('file')->getClientOriginalName();
        
        $folder = 'tiny/'.$fileName;
        
        $upload = Storage::put($folder, $request->file('file'));
        
        return response()->json(['location'=> url("resources/app/uploads/$fileName")]); 
        
    }

Tiny code

tinymce.init({
        selector: 'textarea',  // change this value according to your HTML
        image_class_list: [
        {title: 'img-responsive', value: 'img-responsive'},
        ],
        height: 500,
        setup: function (editor) {
            editor.on('init change', function () {
                editor.save();
            });
        },
        plugins: ['fullscreen', 'print', 'paste', 'lists advlist','autosave','image','pagebreak','table', 'toc', 'searchreplace', 'export','advcode', 'imagetools', 'autolink'],
        toolbar: 'undo redo | styleselect | forecolor | bold italic | alignleft aligncenter alignright alignjustify | outdent indent | link image | code | export | fullscreen | pagebreak',
        export_ignore_elements: [ 'iframe', 'video', 'audio' ],
        image_title: true,
        automatic_uploads: true,
        images_upload_url: base_url + 'uploadImageText',
        file_picker_types: 'image',
        file_picker_callback: function(cb, value, meta) {
            var input = document.createElement('input');
            input.setAttribute('type', 'file');
            input.setAttribute('accept', 'image/*');
            input.onchange = function() {
                var file = this.files[0];

                var reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function () {
                    var id = 'blobid' + (new Date()).getTime();
                    var blobCache =  tinymce.activeEditor.editorUpload.blobCache;
                    var base64 = reader.result.split(',')[1];
                    var blobInfo = blobCache.create(id, file, base64);
                    blobCache.add(blobInfo);
                    cb(blobInfo.blobUri(), { title: file.name });
                };
            };
            input.click();
        },
        content_css: "writer",
        content_style: "body { margin: 0rem auto; max-width: 900px; }" + " p{word-break: break-word !important}" + " .mce-pagebreak { display: block !important; page-break-after: always !important;}",
        pagebreak_split_block: true
    });


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire