Пример #1
0
        /// <summary>
        /// 多文件上传
        /// </summary>
        /// <param name="model"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task <IResultModel <IList <FileInfo> > > Upload(FileUploadMultipleModel model, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException("多文件上传暂未实现");

            //var result = new ResultModel<IList<FileInfo>>();

            //if (model.FormFiles == null || !model.FormFiles.Any())
            //{
            //    if (model.Request.Form.Files != null && model.Request.Form.Files.Any())
            //    {
            //        model.FormFiles = model.Request.Form.Files.ToList();
            //    }
            //}

            //if (model.FormFiles == null || !model.FormFiles.Any())
            //    return result.Failed("请选择文件!");

            //var tasks = new List<Task<FileInfo>>();
            //foreach (var formFile in model.FormFiles)
            //{
            //    tasks.Add(UploadSave(formFile, model.RelativePath, model.RootPath, cancellationToken));
            //}

            //var list = await Task.WhenAll(tasks);

            //return result.Success(list);
        }
        /// <summary>
        /// 多文件上传
        /// </summary>
        /// <param name="model"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IResultModel <IList <FileInfo> > > Upload(FileUploadMultipleModel model, CancellationToken cancellationToken = default)
        {
            var result = new ResultModel <IList <FileInfo> >();

            if (model.FormFiles == null || !model.FormFiles.Any())
            {
                if (model.Request.Form.Files != null && model.Request.Form.Files.Any())
                {
                    model.FormFiles = model.Request.Form.Files.ToList();
                }
            }

            if (model.FormFiles == null || !model.FormFiles.Any())
            {
                return(result.Failed("请选择文件!"));
            }

            var tasks = new List <Task <FileInfo> >();

            foreach (var formFile in model.FormFiles)
            {
                tasks.Add(UploadSave(formFile, model.RelativePath, model.RootPath, cancellationToken));
            }

            var list = await Task.WhenAll(tasks);

            return(result.Success(list));
        }