在任何地方都找不到答案,所以我破解了核心 redactor.js 文件
我添加了
$.Redactor.opts = {
imageUploadExtraParams: {},
到选项并更改帖子以将这些参数包含在pasteClipboardUploadMozilla
和pasteClipboardUpload
pasteClipboardUploadMozilla: function() {
var imgs = this.$editor.find('img[data-mozilla-paste-image]');
$.each(imgs, $.proxy(function(i, s) {
var $s = $(s);
var arr = s.src.split(",");
var data = arr[1]; // raw base64
var contentType = arr[0].split(";")[0].split(":")[1];
var postData = {
contentType: contentType,
data: data,
};
var extraParams = this.opts.imageUploadExtraParams || {};
for (var propName in extraParams) {
postData[propName] = extraParams[propName];
}
$.post(this.opts.clipboardUploadUrl, postData,
并改变了
pasteClipboardUploadMozilla: function() {
var imgs = this.$editor.find('img[data-mozilla-paste-image]');
$.each(imgs, $.proxy(function(i, s) {
var $s = $(s);
var arr = s.src.split(",");
var data = arr[1]; // raw base64
var contentType = arr[0].split(";")[0].split(":")[1];
var postData = {
contentType: contentType,
data: data,
};
var extraParams = this.opts.imageUploadExtraParams || {};
for (var propName in extraParams) {
postData[propName] = extraParams[propName];
}
$.post(this.opts.clipboardUploadUrl, postData,
现在我可以通过添加imageUploadExtraParams
对象来发布额外的参数
$el.redactor({
imageUpload: '/WebUpload/Save',
clipboardUploadUrl: '/WebUpload/Save',
imageUploadExtraParams: {
id: 1234,
name: "test123"
},
});
更新
从 Redacor v10 开始,额外的参数包括在内,只需使用uploadImageFields
$el.redactor({
imageUpload: '/WebUpload/Save',
clipboardUploadUrl: '/WebUpload/Save',
uploadImageFields: {
id: 1234,
name: "test123"
},
});