// NEXT STATION: Services/CustomFileStore.cs public async Task <string> CreateFileInCustomFolder() { // Now it will be the same process as it was with the IMediaFileStore but it will be our ICustomFileStore // this time. The files will be created inside our CustomFiles folder as it was defined in Startup.cs. using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hi there in the custom file storage!"))) { await _customFileStore.CreateFileFromStreamAsync(TestFileRelativePath, stream, true); } var fileInfo = await _customFileStore.GetFileInfoAsync(TestFileRelativePath); return($"Successfully created file in the custom file storage! File size: {fileInfo.Length} bytes."); }
public async Task <ContentResult> Upload() { if (!User.Identity.IsAuthenticated) { return(GetResult(string.Empty, "Unauthorized")); } if (Request.HasFormContentType && Request.Form.Files != null && Request.Form.Files.Count > 0) { var file = Request.Form.Files[0]; if (file != null && file.Length > 0) { var contentItem = await _contentManager.NewAsync("TransformalizeFile"); var part = contentItem.As <TransformalizeFilePart>(); part.OriginalName.Text = file.FileName; var filePath = Path.Combine(Common.GetSafeFilePath(part, HttpContext.User.Identity.Name)); using (var stream = file.OpenReadStream()) { await _formFileStore.CreateFileFromStreamAsync(filePath, stream, true); } var fileInfo = await _formFileStore.GetFileInfoAsync(filePath); part.FullPath.Text = fileInfo.Path; contentItem.Apply(part); await _contentManager.CreateAsync(contentItem); return(GetResult(contentItem.ContentItemId, file.FileName)); } } return(GetResult(string.Empty, "Error")); }