public void Receive(MediaMoverContext context, MediaFile mediaFile, Stream stream) { Guard.NotNull(context, nameof(context)); Guard.NotNull(mediaFile, nameof(mediaFile)); // store data into file if (stream != null && stream.Length > 0) { var filePath = GetPath(mediaFile); if (!_fileSystem.FileExists(filePath)) { // TBD: (mc) We only save the file if it doesn't exist yet. // This should save time and bandwidth in the case where the target // is a cloud based file system (like Azure BLOB). // In such a scenario it'd be advisable to copy the files manually // with other - maybe more performant - tools before performing the provider switch. // Create folder if it does not exist yet var dir = Path.GetDirectoryName(filePath); if (!_fileSystem.FolderExists(dir)) { _fileSystem.CreateFolder(dir); } using (stream) { _fileSystem.SaveStream(filePath, stream); } context.AffectedFiles.Add(filePath); } } }
public void Put(CachedImage cachedImage, Stream stream) { if (PreparePut(cachedImage, stream)) { var path = BuildPath(cachedImage.Path); _fileSystem.SaveStream(path, stream); PostPut(cachedImage, path); } }
public void Put(CachedImage cachedImage, Stream stream) { if (PreparePut(cachedImage, stream)) { var path = BuildPath(cachedImage.Path); _fileSystem.SaveStream(path, stream); cachedImage.Exists = true; cachedImage.File = _fileSystem.GetFile(path); } }
private void Upload(string path) { path = GetRelativePath(path); string message = null; var hasError = false; var width = 0; var height = 0; int.TryParse(GetSetting("MAX_IMAGE_WIDTH"), out width); int.TryParse(GetSetting("MAX_IMAGE_HEIGHT"), out height); var tempDir = FileSystemHelper.TempDirTenant("roxy " + CommonHelper.GenerateRandomInteger().ToString()); try { // copy uploaded files to temp folder and resize them for (var i = 0; i < Request.Files.Count; ++i) { var file = Request.Files[i]; var extension = Path.GetExtension(file.FileName); if (IsAllowedFileType(extension)) { var dest = Path.Combine(tempDir, file.FileName); file.SaveAs(dest); if (GetFileContentType(extension).IsCaseInsensitiveEqual("image")) { ImageResize(dest, dest, width, height); } } else { message = LangRes("E_UploadNotAll"); } } // copy files to file storage foreach (var tempPath in Directory.EnumerateFiles(tempDir, "*", SearchOption.TopDirectoryOnly)) { using (var stream = new FileStream(tempPath, FileMode.Open, FileAccess.Read)) { var name = GetUniqueFileName(path, Path.GetFileName(tempPath)); var newPath = _fileSystem.Combine(path, name); _fileSystem.SaveStream(newPath, stream); } } } catch (Exception exception) { hasError = true; message = exception.Message; } finally { FileSystemHelper.ClearDirectory(tempDir, true); } if (IsAjaxUpload()) { if (message.HasValue()) { Response.Write(GetResultString(message, hasError ? "error" : "ok")); } } else { Response.Write("<script>"); Response.Write("parent.fileUploaded(" + GetResultString(message, hasError ? "error" : "ok") + ");"); Response.Write("</script>"); } }