我试图创建一个自定义ImageFilter
,它要求我暂时将映像写入磁盘,因为我使用的是仅以FileInfo
对象为参数的第三方库。我希望我可以使用IStorageProvider
轻松地写入和获取文件,但似乎无法找到将IStorageFile
转换为FileInfo
或获取当前租户的媒体文件夹的完整路径以自行检索文件的方法。如何从Orchard Media文件夹中获取FileInfo对象?
public class CustomFilter: IImageFilterProvider {
public void ApplyFilter(FilterContext context)
{
if (context.Media.CanSeek)
{
context.Media.Seek(0, SeekOrigin.Begin);
}
// Save temporary image
var fileName = context.FilePath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
if (!string.IsNullOrEmpty(fileName))
{
var tempFilePath = string.Format("tmp/tmp_{0}", fileName);
_storageProvider.TrySaveStream(tempFilePath, context.Media);
IStorageFile temp = _storageProvider.GetFile(tempFilePath);
FileInfo tempFile = ???
// Do all kinds of things with the temporary file
// Convert back to Stream and pass along
context.Media = tempFile.OpenRead();
}
}
}
FileSystemStorageProvider
做一吨繁重的构建路径Media文件夹所以这是一个耻辱,他们不供公众查阅。我宁愿不必复制所有的初始化代码。有没有简单的方法来直接访问媒体文件夹中的文件?
这就是我最终做的。我需要一些额外的技巧来将租户的名称添加到路径中,并且它不是很漂亮,但它至少适用于我的目的。 – Lawyerson