protected async void CreateOrEditClick() { #region 일 업로드 관련 추가 코드 영역 if (selectedFiles != null && selectedFiles.Length > 0) { // 파일 업로드 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { //file.Name = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}{file.Name}"; fileName = file.Name; fileSize = Convert.ToInt32(file.Size); //[A] byte[] 형태 //var ms = new MemoryStream(); //await file.Data.CopyToAsync(ms); //await FileStorageManager.UploadAsync(ms.ToArray(), file.Name, "", true); //[B] Stream 형태 //string folderPath = Path.Combine(WebHostEnvironment.WebRootPath, "files"); await FileStorageManager.UploadAsync(file.Data, file.Name, "", true); Model.FileName = fileName; Model.FileSize = fileSize; } } #endregion if (!int.TryParse(parentId, out int newParentId)) { newParentId = 0; } Model.ParentId = newParentId; Model.ParentKey = Model.ParentKey; if (Model.Id == 0) { // Create await UploadRepositoryAsyncReference.AddAsync(Model); CreateCallback?.Invoke(); } else { // Edit await UploadRepositoryAsyncReference.EditAsync(Model); await EditCallback.InvokeAsync(true); } //IsShow = false; // this.Hide() }
/// <summary> /// /// </summary> /// <param name="directory"></param> /// <param name="file"></param> /// <param name="userId"></param> /// <param name="cancelToken"></param> private async Task <UploadOutput> AddUpload(string directory, string file, string userId, CancellationToken cancelToken = default) { var upload = await _uploadRepository.AddAsync( new UploadDto { Agreement = Agreement + "://", Host = Host + "/", Domain = "/Upload", Directory = "/" + directory, File = "/" + file, OperationTime = DateTimeOffset.Now, OperationUserId = userId }, cancelToken); if (upload != null) { return(new UploadOutput { Id = upload.Id.ToString(), Url = upload.Agreement + upload.Host + upload.Domain + upload.Directory + upload.File }); } return(new UploadOutput { }); }