#17789, #18166: Resizing image in a Blog Post fails from Live Writer

Work Items: 18166, 17789

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-11-29 11:10:17 -08:00
parent 6ee9acc353
commit 198a8283eb

View File

@@ -6,8 +6,8 @@ using System.Xml.Linq;
using JetBrains.Annotations;
using Orchard.Core.XmlRpc;
using Orchard.Core.XmlRpc.Models;
using Orchard.Localization;
using Orchard.Mvc.Extensions;
using Orchard.Utility.Extensions;
using Orchard.Security;
namespace Orchard.Media.Services {
@@ -27,8 +27,12 @@ namespace Orchard.Media.Services {
_authorizationService = authorizationService;
_mediaService = mediaService;
_routeCollection = routeCollection;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public void SetCapabilities(XElement options) {
const string manifestUri = "http://schemas.microsoft.com/wlw/manifest/weblog";
options.SetElementValue(XName.Get("supportsFileUpload", manifestUri), "Yes");
@@ -55,14 +59,22 @@ namespace Orchard.Media.Services {
var user = _membershipService.ValidateUser(userName, password);
if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) {
//TEMP: return appropriate access-denied response for user
throw new ApplicationException("Access denied");
throw new OrchardCoreException(T("Access denied"));
}
var name = file.Optional<string>("name");
var bits = file.Optional<byte[]>("bits");
string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true);
try {
// delete the file if it already exists, e.g. and updated image in a blog post
// it's safe to delete the file as each content item gets a specific folder
_mediaService.DeleteFile(Path.GetDirectoryName(name), Path.GetFileName(name));
}
catch {
// current way to delete a file if it exists
}
string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, false);
return new XRpcStruct().Set("url", url.MakeAbsolute(publicUrl));
}
}