/// <summary>
        /// 게시판 파일 강제 다운로드 기능(/BoardDown/:Id)
        /// </summary>
        public async Task <IActionResult> FileDown(int id)
        {
            var model = await _repository.GetByIdAsync(id);

            if (model == null)
            {
                return(null);
            }
            else
            {
                if (!string.IsNullOrEmpty(model.FileName))
                {
                    byte[] fileBytes = await _fileStorageManager.DownloadAsync(model.FileName, "");

                    if (fileBytes != null)
                    {
                        // DownCount
                        model.DownCount = model.DownCount + 1;
                        await _repository.EditAsync(model);

                        return(File(fileBytes, "application/octet-stream", model.FileName));
                    }
                    else
                    {
                        return(Redirect("/"));
                    }
                }

                return(Redirect("/"));
            }
        }
Esempio n. 2
0
        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()
        }