Fixing media processing on Azure

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-07-10 13:19:39 -07:00
parent 888da5914a
commit 1baae1b43c
3 changed files with 30 additions and 6 deletions

View File

@@ -274,5 +274,25 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
Assert.That(file.Properties.ContentType, Is.EqualTo("application/unknown"));
}
[Test]
public void GetStoragePathShouldReturnAValidLocalPath()
{
_azureBlobStorageProvider.CreateFile("folder1/foo.txt");
var publicPath = _azureBlobStorageProvider.GetPublicUrl("folder1/foo.txt");
var storagePath = _azureBlobStorageProvider.GetStoragePath(publicPath);
Assert.IsNotNull(storagePath);
Assert.That(storagePath, Is.EqualTo("folder1/foo.txt"));
}
[Test]
public void GetStoragePathShouldReturnNullIfPathIsNotLocal()
{
var storagePath = _azureBlobStorageProvider.GetStoragePath("foo");
Assert.IsNull(storagePath);
}
}
}

View File

@@ -46,10 +46,10 @@ namespace Orchard.Azure.FileSystems.Media {
/// <returns>The local path.</returns>
public string GetStoragePath(string url) {
if (url.StartsWith(_absoluteRoot)) {
return url.Substring(_absoluteRoot.Length);
return url.Substring(Combine(_absoluteRoot, "/").Length);
}
return url;
return null;
}
public string GetRelativePath(string path) {

View File

@@ -160,12 +160,15 @@ namespace Orchard.MediaProcessing.Services {
// TODO: Update this method once the storage provider has been updated
private Stream GetImage(string path) {
var request = _services.WorkContext.HttpContext.Request;
var storagePath = _storageProvider.GetStoragePath(path);
if (storagePath != null) {
var file = _storageProvider.GetFile(storagePath);
return file.OpenRead();
try {
var file = _storageProvider.GetFile(storagePath);
return file.OpenRead();
}
catch {
Logger.Error("path:" + path + " storagePath:" + storagePath);
}
}
// http://blob.storage-provider.net/my-image.jpg
@@ -175,6 +178,7 @@ namespace Orchard.MediaProcessing.Services {
// ~/Media/Default/images/my-image.jpg
if (VirtualPathUtility.IsAppRelative(path)) {
var request = _services.WorkContext.HttpContext.Request;
return new WebClient().OpenRead(new Uri(request.Url, VirtualPathUtility.ToAbsolute(path)));
}