Merge branch 'v8/feature/2349AB-RTE-Image-Upload' into v8/feature/2438AB-RTE-Image-Config-MediaFolder

# Conflicts:
#	src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs
#	src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs
This commit is contained in:
Warren Buckley
2019-09-11 12:20:27 +01:00
3 changed files with 20 additions and 20 deletions

View File

@@ -36,10 +36,8 @@ namespace Umbraco.Web.Editors
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
// Backoffice user ID (needed for unique folder path) to help with concurrent users
// to avoid filename clash along with UTC current time
var userId = Security.CurrentUser.Id;
var imageTempPath = IOHelper.MapPath(SystemDirectories.TempImageUploads + "/" + userId + "_" + DateTimeOffset.UtcNow.ToUnixTimeSeconds());
// Create an unique folder path to help with concurrent users to avoid filename clash
var imageTempPath = IOHelper.MapPath(SystemDirectories.TempImageUploads + "/" + Guid.NewGuid().ToString());
// Temp folderpath (Files come in as bodypart & will need to move/saved into imgTempPath
var folderPath = IOHelper.MapPath(SystemDirectories.TempFileUploads);

View File

@@ -85,9 +85,9 @@ namespace Umbraco.Web.PropertyEditors
/// Format the data for the editor
/// </summary>
/// <param name="property"></param>
/// <param name="dataTypeService"></param>Rte
/// <param name="dataTypeService"></param>
/// <param name="culture"></param>
/// <param name="segment"></param>te
/// <param name="segment"></param>
public override object ToEditor(Property property, IDataTypeService dataTypeService, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);

View File

@@ -20,6 +20,8 @@ namespace Umbraco.Web.Templates
/// </summary>
public static class TemplateUtilities
{
const string TemporaryImageDataAttribute = "data-tmpimg";
internal static string ParseInternalLinks(string text, bool preview, UmbracoContext umbracoContext)
{
using (umbracoContext.ForcedPreview(preview)) // force for url provider
@@ -194,46 +196,46 @@ namespace Umbraco.Web.Templates
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
var tmpImages = htmlDoc.DocumentNode.SelectNodes("//img[@data-tmpimg]");
var tmpImages = htmlDoc.DocumentNode.SelectNodes($"//img[@{TemporaryImageDataAttribute}]");
if (tmpImages == null || tmpImages.Count == 0)
return html;
foreach (var img in tmpImages)
{
// The data attribute contains the path to the tmp img to persist as a media item
var tmpImgPath = img.GetAttributeValue("data-tmpimg", string.Empty);
var tmpImgPath = img.GetAttributeValue(TemporaryImageDataAttribute, string.Empty);
if (string.IsNullOrEmpty(tmpImgPath))
continue;
var absTmpImgPath = IOHelper.MapPath(tmpImgPath);
var fileName = Path.GetFileName(absTmpImgPath);
var absoluteTempImagePath = IOHelper.MapPath(tmpImgPath);
var fileName = Path.GetFileName(absoluteTempImagePath);
var safeFileName = fileName.ToSafeFileName();
var mediaItemName = safeFileName.ToFriendlyName();
var f = mediaService.CreateMedia(mediaItemName, mediaParentFolder, Constants.Conventions.MediaTypes.Image, userId);
var fileInfo = new FileInfo(absTmpImgPath);
var mediaFile = mediaService.CreateMedia(mediaItemName, mediaParentFolder, Constants.Conventions.MediaTypes.Image, userId);
var fileInfo = new FileInfo(absoluteTempImagePath);
var fs = fileInfo.OpenReadWithRetry();
if (fs == null) throw new InvalidOperationException("Could not acquire file stream");
using (fs)
var fileStream = fileInfo.OpenReadWithRetry();
if (fileStream == null) throw new InvalidOperationException("Could not acquire file stream");
using (fileStream)
{
f.SetValue(contentTypeBaseServiceProvider, Constants.Conventions.Media.File, safeFileName, fs);
mediaFile.SetValue(contentTypeBaseServiceProvider, Constants.Conventions.Media.File, safeFileName, fileStream);
}
mediaService.Save(f, userId);
mediaService.Save(mediaFile, userId);
// Add the UDI to the img element as new data attribute
var udi = f.GetUdi();
var udi = mediaFile.GetUdi();
img.SetAttributeValue("data-udi", udi.ToString());
//Get the new persisted image url
var mediaTyped = Current.UmbracoHelper.Media(f.Id);
var mediaTyped = Current.UmbracoHelper.Media(mediaFile.Id);
var location = mediaTyped.Url;
img.SetAttributeValue("src", location);
// Remove the data attribute (so we do not re-process this)
img.Attributes.Remove("data-tmpimg");
img.Attributes.Remove(TemporaryImageDataAttribute);
}
return htmlDoc.DocumentNode.OuterHtml;