我試圖創建一個自定義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