An object of additional header key/value pairs to send along with
requests using the XMLHttpRequest transport. See [[Ajax.defaultAjaxOptions]]
Type: {function} uploader.prepareData Before send file will called this function. First argument it gets
new FormData (), you can use this if you want add some POST
parameter.
Jodit.make('#editor',{ uploader:{ url:'connector/index.php?action=upload',// This is a required parameter prepareData:function(formdata){ formdata.append('id',24);// $_POST['id'] on server formdata.append('name','Some parameter');// $_POST['name'] on server } } });
// buildData can return Promise // this example demonstrate how send file like as base64 text. Work only in Firefox and Chrome consteditor=Jodit.make('#editor',{ uploader:{ url:'index.php?action=fileUpload', queryBuild:function(data){ returnJSON.stringify(data); }, contentType:function(){ return'application/json'; }, buildData:function(data){ returnnewPromise(function(resolve,reject){ varreader=newFileReader(); reader.readAsDataURL(data.getAll('files[0]')[0]); reader.onload=function(){ returnresolve({ image:reader.result }); }; reader.onerror=function(error){ reject(error); }; }); } } });
File uploader module
The module for uploading files to the server is configured via the
uploader
namespace and has [[IUploaderOptions]] options.Here are some of them:
Options
uploader.url
string
Point of entry for file uploader. This is a required parameter.
uploader.format
string
The format of the received data
uploader.headers
string
An object of additional header key/value pairs to send along with requests using the XMLHttpRequest transport. See [[Ajax.defaultAjaxOptions]] Type: {function} uploader.prepareData Before send file will called this function. First argument it gets new FormData (), you can use this if you want add some POST parameter.
uploader.data
object
|boolean
POST parameters
Example prepareData
uploader.isSuccess
function
Check if received data was positive
uploader.getMessage
function
If you need display a message use this
uploader.process
function
The method of processing data received from the server. Must return special object:
uploader.error
function
Process negative situation. For example file wasn't uploaded because of file permission
uploader.defaultHandlerSuccess
function
Default success result processor. In first param it get
uploader.process
resultuploader.defaultHandlerError
function
Default error result processor.
uploader.processFileName
function
(key, file, name) => [key, file, name]
The method can be used to change the name of the uploaded file.
Examples
Example 1
Example 2
Example 3