V10: Fix to allow dragged images in the rich text editor to be correctly uploaded (#13016)
* update string extensions IsFullPath to support more filepaths with new built-in Path.IsPathFullyQualified * resolve TODO to switch to Path.IsPathFullyQualified supported from .NET Standard 2.1 * Use content root instead of web root for uploaded images * Un-break a breaking change * handle special parsing of AngularJS json response * change htmlId selector to support html id's with numbers * remove bad test case * test IsFullPath without tricky UNC paths that are not useful Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -222,9 +222,7 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s
|
||||
}
|
||||
|
||||
function uploadImageHandler(blobInfo, success, failure, progress){
|
||||
let xhr, formData;
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', Umbraco.Sys.ServerVariables.umbracoUrls.tinyMceApiBaseUrl + 'UploadImage');
|
||||
|
||||
xhr.onloadstart = function(e) {
|
||||
@@ -248,18 +246,33 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s
|
||||
};
|
||||
|
||||
xhr.onload = function () {
|
||||
let json;
|
||||
|
||||
if (xhr.status < 200 || xhr.status >= 300) {
|
||||
failure('HTTP Error: ' + xhr.status);
|
||||
return;
|
||||
}
|
||||
|
||||
json = JSON.parse(xhr.responseText);
|
||||
let data = xhr.responseText;
|
||||
|
||||
// The response is fitted as an AngularJS resource response and needs to be cleaned of the AngularJS metadata
|
||||
data = data.split("\n");
|
||||
|
||||
if (!data.length > 1) {
|
||||
failure('Unrecognized text string: ' + data);
|
||||
return;
|
||||
}
|
||||
|
||||
let json = {};
|
||||
|
||||
try {
|
||||
json = JSON.parse(data[1]);
|
||||
} catch (e) {
|
||||
failure('Invalid JSON: ' + data + ' - ' + e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json || typeof json.tmpLocation !== 'string') {
|
||||
failure('Invalid JSON: ' + xhr.responseText);
|
||||
return;
|
||||
failure('Invalid JSON: ' + data);
|
||||
return;
|
||||
}
|
||||
|
||||
// Put temp location into localstorage (used to update the img with data-tmpimg later on)
|
||||
@@ -271,7 +284,7 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s
|
||||
success(blobInfo.blobUri());
|
||||
};
|
||||
|
||||
formData = new FormData();
|
||||
const formData = new FormData();
|
||||
formData.append('file', blobInfo.blob(), blobInfo.blob().name);
|
||||
|
||||
xhr.send(formData);
|
||||
@@ -435,7 +448,7 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s
|
||||
|
||||
|
||||
if (args.htmlId) {
|
||||
config.selector = "#" + args.htmlId;
|
||||
config.selector = `[id="${args.htmlId}"]`;
|
||||
} else if (args.target) {
|
||||
config.target = args.target;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user