本文整理汇总了C#中IFormFile.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IFormFile.ToString方法的具体用法?C# IFormFile.ToString怎么用?C# IFormFile.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormFile
的用法示例。
在下文中一共展示了IFormFile.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessUpload
private async Task<JsonResult> ProcessUpload(IFormFile file)
{
Trace.TraceInformation("Process upload for {0}", file.ToString());
var t = DateTime.UtcNow - new DateTime(1970, 1, 1);
var epoch = (int)t.TotalSeconds;
var sourceName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var filePath = Path.GetTempFileName();
string url = null;
// Save locally
using (var stream = System.IO.File.OpenWrite(filePath))
{
await file.CopyToAsync(stream);
}
try
{
var resultPaths = ConvertFiles(filePath, sourceName);
if (resultPaths != null && resultPaths.Any())
{
foreach (var path in resultPaths)
{
Trace.TraceInformation("Moving to blob store: {0}", path);
var blobUri = await _storage.UploadFileToBlob(path, Path.GetFileName(path));
// Hack - Grab the destination URI for use later
if (blobUri.Contains(".dat"))
{
url = blobUri.Replace(".dat", string.Empty);
}
}
// update project name if appropriate
string projectName = Path.GetFileNameWithoutExtension(sourceName);
var projects = _storage.GetProjectsForUser(GetEmailFromUser());
if (projects.Where(p => string.Equals(p.Name, projectName, StringComparison.OrdinalIgnoreCase)).Any())
{
int versionNumber = projects.Count(p => p.Name.Contains(projectName)) + 1;
projectName = string.Format("{0} (v{1})", projectName, versionNumber);
}
_storage.SaveFileToTables(projectName, url, GetEmailFromUser());
}
}
catch (Exception ex)
{
var result = new JsonResult(new { error = "The server failed to process this file. Please verify source data is compatible." });
result.StatusCode = 500;
return result;
}
return Json(new { thumbnail = "url" + ".jpg" });
}