Fixes up a few issues found with media uploading

This commit is contained in:
Shannon
2013-08-28 10:45:50 +10:00
parent f03180e6f8
commit dedaa2125d
4 changed files with 31 additions and 19 deletions

View File

@@ -135,14 +135,15 @@ namespace Umbraco.Core.IO
{
EnsureFileSupportsResizing();
var fs = _fs.OpenFile(Path);
var image = Image.FromStream(fs);
var fileWidth = image.Width;
var fileHeight = image.Height;
fs.Close();
image.Dispose();
_size = new Size(fileWidth, fileHeight);
using (var fs = _fs.OpenFile(Path))
{
using (var image = Image.FromStream(fs))
{
var fileWidth = image.Width;
var fileHeight = image.Height;
_size = new Size(fileWidth, fileHeight);
}
}
}
return _size.Value;
}

View File

@@ -120,7 +120,7 @@ function imageHelper() {
return imagePath.substr(0, imagePath.lastIndexOf('.')) + "_thumb" + ".jpg";
},
detectIfImageByExtension: function(imagePath) {
var lowered = imagePath;
var lowered = imagePath.toLowerCase();
var ext = lowered.substr(lowered.lastIndexOf(".") + 1);
return ("," + Umbraco.Sys.ServerVariables.umbracoSettings.imageFileTypes + ",").indexOf("," + ext + ",") !== -1;
}

View File

@@ -218,20 +218,28 @@ namespace Umbraco.Web.Editors
}
//short hand to use with the uploader in the media dialog
public HttpResponseMessage PostAddFile(int parentId)
public HttpResponseMessage PostAddFile()
{
var context = UmbracoContext.HttpContext;
if(context.Request.Files.Count > 0)
{
var postedFile = context.Request.Files[0];
var name = postedFile.FileName;
if (context.Request.Form.Count > 0)
{
int parentId;
if (int.TryParse(context.Request.Form[0], out parentId))
{
var file = context.Request.Files[0];
var name = file.FileName;
var mediaService = base.ApplicationContext.Services.MediaService;
var f = mediaService.CreateMedia(name, parentId, Constants.Conventions.MediaTypes.Image);
f.SetValue(Constants.Conventions.Media.File, postedFile);
mediaService.Save(f);
var mediaService = base.ApplicationContext.Services.MediaService;
var f = mediaService.CreateMedia(name, parentId, Constants.Conventions.MediaTypes.Image);
f.SetValue(Constants.Conventions.Media.File, file);
mediaService.Save(f);
return new HttpResponseMessage(HttpStatusCode.OK);
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
}
return new HttpResponseMessage(HttpStatusCode.NotFound);

View File

@@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Linq;
using System.Xml;
using Umbraco.Core;
@@ -101,9 +102,11 @@ namespace Umbraco.Web.PropertyEditors
private static void FillProperties(XmlNode uploadFieldConfigNode, IContentBase content, UmbracoMediaFile um)
{
var size = um.SupportsResizing ? (Size?)um.GetDimensions() : null;
// only add dimensions to web images
UpdateContentProperty(uploadFieldConfigNode, content, "widthFieldAlias", um.SupportsResizing ? um.GetDimensions().Width.ToString() : string.Empty);
UpdateContentProperty(uploadFieldConfigNode, content, "heightFieldAlias", um.SupportsResizing ? um.GetDimensions().Height.ToString() : string.Empty);
UpdateContentProperty(uploadFieldConfigNode, content, "widthFieldAlias", size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty);
UpdateContentProperty(uploadFieldConfigNode, content, "heightFieldAlias", size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty);
UpdateContentProperty(uploadFieldConfigNode, content, "lengthFieldAlias", um.Length);
UpdateContentProperty(uploadFieldConfigNode, content, "extensionFieldAlias", um.Extension);