Esempio n. 1
0
        public ResultDto <AttachDto> Upload([FromForm] IFormFile file, [FromForm] Guid attachGuid)
        {
            if (!Directory.Exists(_uploadAttachPath))
            {
                Directory.CreateDirectory(_uploadAttachPath);
            }
            string fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
            string filePath = Path.Combine(_uploadAttachPath, fileName);

            using (FileStream stream = new FileStream(filePath, FileMode.Create))
            {
                file.CopyTo(stream);
            }
            var dto = new AttachSaveDto()
            {
                save_name   = fileName,
                size        = Convert.ToInt32(file.Length),
                ext         = Path.GetExtension(file.FileName),
                name        = file.FileName,
                attach_guid = attachGuid
            };

            return(_service.Create(dto));
        }