public async Task AcceptCameraUpload(string deviceId, Stream stream, LocalFileInfo file) { var path = GetUploadPath(deviceId); if (!string.IsNullOrWhiteSpace(file.Album)) { path = Path.Combine(path, _fileSystem.GetValidFilename(file.Album)); } Directory.CreateDirectory(path); path = Path.Combine(path, file.Name); _libraryMonitor.ReportFileSystemChangeBeginning(path); try { using (var fs = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) { await stream.CopyToAsync(fs).ConfigureAwait(false); } _repo.AddCameraUpload(deviceId, file); } finally { _libraryMonitor.ReportFileSystemChangeComplete(path, true); } }
public async Task AcceptCameraUpload(string deviceId, Stream stream, LocalFileInfo file) { var device = GetDevice(deviceId, false); var uploadPathInfo = GetUploadPath(device); var path = uploadPathInfo.Item1; if (!string.IsNullOrWhiteSpace(file.Album)) { path = Path.Combine(path, _fileSystem.GetValidFilename(file.Album)); } path = Path.Combine(path, file.Name); path = Path.ChangeExtension(path, MimeTypes.ToExtension(file.MimeType) ?? "jpg"); _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); await EnsureLibraryFolder(uploadPathInfo.Item2, uploadPathInfo.Item3).ConfigureAwait(false); _libraryMonitor.ReportFileSystemChangeBeginning(path); try { using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read)) { await stream.CopyToAsync(fs).ConfigureAwait(false); } _repo.AddCameraUpload(deviceId, file); } finally { _libraryMonitor.ReportFileSystemChangeComplete(path, true); } if (CameraImageUploaded != null) { EventHelper.FireEventIfNotNull(CameraImageUploaded, this, new GenericEventArgs <CameraImageUploadInfo> { Argument = new CameraImageUploadInfo { Device = device, FileInfo = file } }, _logger); } }