mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing media processing on Azure
--HG-- branch : 1.x
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -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) {
|
||||
|
@@ -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)));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user