GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.38k stars 4.06k forks source link

How to add Uploaded image in asset manager ? #216

Closed aliassad closed 7 years ago

aliassad commented 7 years ago

here is the ajax call which is uploading image file in assests folder

changes in assetManager/Config/config.js

module.exports =  {
  // Default assets
  assets: [],

  // Style prefix
  stylePrefix: 'am-',

  // Url where uploads will be send, set false to disable upload
  upload: 'http://localhost/grapeJs/src/file_uploader/fileUpload.php',

  // Text on upload input
  uploadText: 'Drop files here or click to upload',

  // Label for the add button
  addBtnText: 'Add image',

  // Custom uploadFile function
 // @example
  uploadFile: function(e) {
    var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
    // ...send somewhere
      console.log(files);

      var formData = new FormData();

      for(var i in files){
          formData.append('file-'+i, files[i])
      }

      $.ajax({url: 'http://localhost/grapeJs/src/file_uploader/fileUpload.php',
          type: 'POST',
          data: formData,
          contentType:false,
          crossDomain: true,
          mimeType: "multipart/form-data",
          processData:false,
          success: function(result){
          console.log(result);

      }});

  }

 //  uploadFile: '',
};

How can i add this image file also in assets manager

artf commented 7 years ago
$.ajax({url: 'http://localhost/grapeJs/src/file_uploader/fileUpload.php',
          type: 'POST',
          data: formData,
          contentType:false,
          crossDomain: true,
          mimeType: "multipart/form-data",
          processData:false,
          success: function(result){
            var images = result.data; // <- should be an array of uploaded images
            editor. AssetManager.add(images);
          }
});
lock[bot] commented 4 years ago

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.