Example #1
0
        public IActionResult GetSeedndImg(int seedid)
        {
            if (_productRepository.GetSeed(seedid) == null)
            {
                return(StatusCode(500, "不存在"));
            }

            var        model = _productRepository.GetFile(seedid);
            FilesPrint fhelp = new FilesPrint();

            byte[] bt = fhelp.ReadFile(fhelp.readURL(model.FileUrl));
            if (bt == null)
            {
                return(StatusCode(500, "读取异常"));
            }
            return(Ok(new FileUpDownLoadToByteDto
            {
                FID = model.FID,
                FileClass = model.FileClass,
                FileName = model.FileName,

                SeedID = model.seed.SeedID,
                Bytes = bt
            }));
        }
Example #2
0
        public IActionResult AddSeedAndImg([FromBody] FileUpDownLoadToByteDto dto)
        {
            if (dto.Bytes == null || dto.FileName == null)
            {
                return(BadRequest("空异常"));
            }
            FilesPrint fhelp   = new FilesPrint();
            string     fileUrl = fhelp.PrintFileCreate(ServiceConfigs.FileUpDirectory, dto.Bytes);

            if (fileUrl == null)
            {
                return(StatusCode(500, "存储错误"));
            }
            if (_productRepository.GetSeed(dto.SeedID) == null)
            {
                return(StatusCode(500, "不存在该编号产品"));
            }
            var model = new FileUpDownload()
            {
                FileClass = dto.FileClass,
                FileName  = dto.FileName,
                FileUrl   = fileUrl,

                seed = _productRepository.GetSeed(dto.SeedID)
            };

            _productRepository.AddFile(model);
            if (!_productRepository.Save())
            {
                return(StatusCode(500, "上传失败,转储数据库异常"));
            }
            return(NoContent());
        }
        public IActionResult Post(string type, IFormCollection files)
        {
            long size = files.Sum(f => f.Key.Length);

            //限制文件大小
            if (size > 1024 * 1024 * 5 * 20)
            {
                return(BadRequest("文件超过限制大小100MB"));
            }
            List <string> filePathREsultList = new List <string>();

            foreach (var file in files.Files)
            {
                //-0-0-0-0-0-0-0-0-------------暂存
                var        fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                string     filePath = ServiceConfigs.FileUpDirectory;
                FilesPrint fp       = new FilesPrint();
                string     suffix   = fileName.Split('.')[1];
                if ((!pictureFormatArray.Contains(suffix)))
                {
                    return(StatusCode(500, "文件格式错误"));
                }
                fileName = Guid.NewGuid() + "." + suffix;
                string fileFullName = filePath + fileName;
                using (FileStream fs = System.IO.File.Create(fileFullName))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
                filePathREsultList.Add($"/src/Pictures/{fileName}");
            }
            string message = $"{files.Count} file(s)/{size} bytes uploaded  successfully!";

            return(Ok(message));
        }
Example #4
0
        public IActionResult getSeedImg(int seedid)
        {
            if (seedid < 0)
            {
                return(BadRequest());
            }
            var model = _productRepository.GetSeed(seedid);

            if (model == null)
            {
                return(StatusCode(500, "获取失败"));
            }
            //var list = new List<SeedDto>();
            SeedAndImgDto seedDto = new SeedAndImgDto
            {
                SellerID    = model.SellerID,
                Species     = model.Species,
                Brand       = model.Brand,
                Details     = model.Details,
                SeedClass   = model.SeedClass,
                Exhibitions = model.Exhibitions,
                MakertID    = model.MakertID,
                MakertName  = _productRepository.GetSeller(model.SellerID).MarkerName,
                Name        = model.Name,

                Price = model.Price,
            };
            var filemodel = _productRepository.GetFile(model.SeedID);
            FileUpDownLoadToByteDto filedto = new FileUpDownLoadToByteDto
            {
                FID       = filemodel.FID,
                FileClass = filemodel.FileClass,
                FileUrl   = filemodel.FileUrl,
                FileName  = filemodel.FileName,
                SeedID    = filemodel.seed.SeedID
            };

            try
            {
                string     Imgurl = _productRepository.GetFile(model.SeedID).FileUrl;
                FilesPrint fp     = new FilesPrint();

                filedto.Bytes             = fp.ReadFile(fp.readURL(Imgurl));
                seedDto.FileUpDownLoadDto = filedto;
            }
            catch (Exception)
            {
                filedto.Bytes = null;
                throw;
            }


            return(Ok(seedDto));
        }
        public IActionResult Post(string type, IFormFile file)
        {
            long size = file.Length;

            //限制文件大小
            if (size > 1024 * 1024 * 5 * 20)
            {
                return(BadRequest("文件超过限制大小100MB"));
            }
            List <string> filePathREsultList = new List <string>();

            //-0-0-0-0-0-0-0-0-------------暂存
            var        fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
            string     filePath = ServiceConfigs.FileUpDirectory;
            FilesPrint fp       = new FilesPrint();
            string     suffix   = fileName.Split('.')[1];

            if ((!pictureFormatArray.Contains(suffix)))
            {
                return(StatusCode(500, "文件格式错误"));
            }
            filePath += @"\" + System.DateTime.Now.Year.ToString() + @"\" + System.DateTime.Now.Month.ToString() + @"\" + System.DateTime.Now.Day.ToString();//文件夹
            UnixStamp ustamp = new UnixStamp();

            if (!(Directory.Exists(filePath)))
            {
                Directory.CreateDirectory(filePath);
            }
            fileName = @"\" + ustamp.DateTimeToStamp(System.DateTime.Now) + "." + suffix;
            string fileFullName = filePath + fileName;

            try
            {
                using (FileStream fs = System.IO.File.Create(fileFullName))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
            }
            catch (Exception e)
            {
                string ss = e.ToString();
                return(StatusCode(404, $"存储错误+filefullname={fileFullName}"));

                throw;
            }

            filePathREsultList.Add($"/src/Pictures/{fileName}");

            string message = $" file(s)/{size} bytes uploaded  successfully! fileurl={fileFullName}";

            return(Ok(message));
        }
Example #6
0
        public IActionResult PostSeedImg([FromBody] SeedAndImgDto seedDto)
        {
            if (seedDto == null)
            {
                return(BadRequest());
            }
            var model = new Seed
            {
                SellerID    = seedDto.SellerID,
                Species     = seedDto.Species,
                Brand       = seedDto.Brand,
                Details     = seedDto.Details,
                SeedClass   = seedDto.SeedClass,
                Exhibitions = seedDto.Exhibitions,
                Name        = seedDto.Name,

                Price = seedDto.Price
            };

            if (seedDto.FileUpDownLoadDto != null)
            {
                FileUpDownload fileUpDownload = new FileUpDownload
                {
                    FileClass = seedDto.FileUpDownLoadDto.FileClass,
                    FileName  = seedDto.FileUpDownLoadDto.FileName,
                    seed      = _productRepository.GetSeed(seedDto.SeedID),
                };

                try
                {
                    string     fileurl;
                    FilesPrint fp = new FilesPrint();
                    fileurl = fp.PrintFileCreate(ServiceConfigs.FileUpDirectory, seedDto.FileUpDownLoadDto.Bytes);
                    fileUpDownload.FileUrl = fp.readURL(fileurl);
                    model.fileUpDownloads.Add(fileUpDownload);
                }
                catch (Exception)
                {
                    return(StatusCode(500, "传入字节流文件错误"));

                    throw;
                }
            }

            _productRepository.AddSeed(model);
            if (!_productRepository.Save())
            {
                return(StatusCode(500, "存储失败"));
            }
            return(Ok());
        }
Example #7
0
        public IActionResult PutSeedAndImg(int seedid, [FromBody] FileUpDownLoadToByteDto dto)
        {
            if (dto.Bytes == null || dto.FileName == null)
            {
                return(BadRequest("空异常"));
            }
            FilesPrint fhelp = new FilesPrint();
            var        url   = _productRepository.GetFile(seedid).FileUrl;

            if (url == null)
            {
                StatusCode(500, "服务器文件丢失");
            }
            ;
            int fileUrl = fhelp.PrintFileUpdate(fhelp.readURL(url), dto.Bytes);

            if (fileUrl == 0)
            {
                return(StatusCode(500, "存入失败"));
            }
            if (fileUrl == null)
            {
                return(StatusCode(500, "存储错误"));
            }
            if (_productRepository.GetSeed(dto.SeedID) == null)
            {
                return(StatusCode(500, "不存在该编号产品"));
            }
            var model = _productRepository.GetFile(dto.SeedID);

            model.FileClass = dto.FileClass;
            model.FileName  = dto.FileName;
            model.FileUrl   = dto.FileUrl;

            model.seed = _productRepository.GetSeed(dto.SeedID);



            if (!_productRepository.Save())
            {
                return(StatusCode(500, "上传失败,转储数据库异常"));
            }
            return(NoContent());
        }
Example #8
0
        public IActionResult AddSeedAndImg(IFormFile file, FileUpDownLoadGetDto dtos)
        {
            if (file == null || file.ContentDisposition.Length <= 0 || file.FileName == null)
            {
                return(BadRequest("空异常"));
            }
            FileUpDownLoadAndFileGetDto dto = new FileUpDownLoadAndFileGetDto
            {
                file      = file,
                FileClass = dtos.FileClass,
                FileUrl   = dtos.FileUrl,
                SeedID    = dtos.SeedID
            };

            string fileUrl = _fileService.PrintFileCreate(dto.file);

            FileStreamPandO.FilesPrint fp = new FilesPrint();
            fileUrl = fp.SaveSRC(fileUrl);
            if (fileUrl == null)
            {
                return(StatusCode(500, "存储错误"));
            }
            if (_productRepository.GetSeed(dto.SeedID) == null)
            {
                return(StatusCode(500, "不存在该编号产品"));
            }
            var model = new FileUpDownload()
            {
                FileClass = dto.FileClass,
                FileName  = file.FileName,
                FileUrl   = fileUrl,

                seed = _productRepository.GetSeed(dto.SeedID)
            };

            _productRepository.AddFile(model);
            if (!_productRepository.Save())
            {
                return(StatusCode(500, "上传失败,转储数据库异常"));
            }
            return(NoContent());
        }
        /// <summary>
        /// 返回存储路径
        /// </summary>
        /// <param name="url"></param>
        /// <param name="file"></param>
        /// <returns>数据库存储路径!!! </returns>
        public string PrintFileCreate(IFormFile file)
        {
            var        fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
            string     filePath = ServiceConfigs.FileUpDirectory;
            FilesPrint fp       = new FilesPrint();
            string     suffix   = fileName.Split('.')[1];

            if ((!pictureFormatArray.Contains(suffix)))
            {
                _logger.LogWarning("+文件类型错误+");
                return(null);
            }
            filePath += @"\" + System.DateTime.Now.Year.ToString() + @"\" + System.DateTime.Now.Month.ToString() + @"\" + System.DateTime.Now.Day.ToString();//文件夹
            UnixStamp ustamp = new UnixStamp();

            if (!(Directory.Exists(filePath)))
            {
                Directory.CreateDirectory(filePath);
            }
            fileName = @"\" + ustamp.DateTimeToStamp(System.DateTime.Now) + "." + suffix;
            string fileFullName = filePath + fileName;

            try
            {
                using (FileStream fs = System.IO.File.Create(fileFullName))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
            }
            catch (Exception e)
            {
                string ss = e.ToString();
                _logger.LogError($"+存储异常+{ss}");
                return(null);
            }
            FileStreamPandO.FilesPrint f = new FilesPrint();
            return(f.SaveSRC(fileFullName));
        }