当前位置: 首页>>代码示例>>C#>>正文


C# IFormFile.CopyToAsync方法代码示例

本文整理汇总了C#中IFormFile.CopyToAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IFormFile.CopyToAsync方法的具体用法?C# IFormFile.CopyToAsync怎么用?C# IFormFile.CopyToAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFormFile的用法示例。


在下文中一共展示了IFormFile.CopyToAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GuardarImagen

        private async Task<bool> GuardarImagen(IFormFile imagen, int personajeId)
        {
            bool resultado = true;

            string carpetaImagenes = Path.Combine(_environment.WebRootPath, "personajes");
            string extension = Path.GetExtension(imagen.FileName);

            if (!EsExtensionValida(extension))
            {
                resultado = false;
                _mensaje = "La extension de la imagen no es valida. Solo se admiten JPG, JPEG, GIF y PNG";
            }
            if (resultado && imagen.Length > 1024*1024)
            {
                resultado = false;
                _mensaje = "Te has colado; la imagen no debe ser mayor de 1 mega";
            }
            if ( resultado && imagen.Length > 0)
            {
                using (var fileStream = new FileStream(Path.Combine(carpetaImagenes, personajeId.ToString() + ".png"), FileMode.Create))
                {
                    await imagen.CopyToAsync(fileStream);
                }
            }

            return resultado;
        }
开发者ID:herruzojm,项目名称:Cronica,代码行数:27,代码来源:ServicioPersonajes.cs

示例2: Create

        public async Task<IActionResult> Create([Bind] Participant partner, IFormFile image)
        {
            if (this.ModelState.IsValid)
            {
                var uploads = Path.Combine(this.environment.WebRootPath, "uploads/participants");
                if (!Directory.Exists(uploads))
                {
                    Directory.CreateDirectory(uploads);
                }

                if (image.Length > 0)
                {
                    var fileName = $"{Guid.NewGuid()}.{image.FileName}";
                    using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                    {
                        await image.CopyToAsync(fileStream);
                        partner.ImgPath = $"/uploads/participants/{fileName}";
                    }
                }

                this.context.Add(partner);
                await this.context.SaveChangesAsync();
                return this.RedirectToAction("Index");
            }

            return this.View(partner);
        }
开发者ID:Zashikivarashi,项目名称:Autosation.ru,代码行数:27,代码来源:ParticipantsController.cs

示例3: UploadDocumentAsync

 public async Task UploadDocumentAsync(IFormFile file)
 {
   using (var fileStream = new FileStream(Path.Combine(_documentUploadConfiguration.UploadPath, file.FileName), FileMode.Create))
   {
     await file.CopyToAsync(fileStream);
   }
 }
开发者ID:Research-Institute,项目名称:emr-api,代码行数:7,代码来源:EmrDocumentRepository.cs

示例4: ProcessUpload

        private async Task<JsonResult> ProcessUpload(IFormFile file)
        {
            Trace.TraceInformation("Process upload for {0}", file.ToString());

            var t = DateTime.UtcNow - new DateTime(1970, 1, 1);
            var epoch = (int)t.TotalSeconds;
            var sourceName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
            var filePath = Path.GetTempFileName();
            string url = null;

            // Save locally
            using (var stream = System.IO.File.OpenWrite(filePath))
            {
                await file.CopyToAsync(stream);
            }
            
            try
            {
                var resultPaths = ConvertFiles(filePath, sourceName);
            

                if (resultPaths != null && resultPaths.Any())
                {
                    foreach (var path in resultPaths)
                    {
                        Trace.TraceInformation("Moving to blob store: {0}", path);
                        var blobUri = await _storage.UploadFileToBlob(path, Path.GetFileName(path));

                        // Hack - Grab the destination URI for use later
                        if (blobUri.Contains(".dat"))
                        {
                            url = blobUri.Replace(".dat", string.Empty);
                        }
                    
                    }

                    // update project name if appropriate
                    string projectName = Path.GetFileNameWithoutExtension(sourceName);
                    var projects = _storage.GetProjectsForUser(GetEmailFromUser());

                    if (projects.Where(p => string.Equals(p.Name, projectName, StringComparison.OrdinalIgnoreCase)).Any())
                    {
                        int versionNumber = projects.Count(p => p.Name.Contains(projectName)) + 1;
                        projectName = string.Format("{0} (v{1})", projectName, versionNumber);
                    }
                    _storage.SaveFileToTables(projectName, url, GetEmailFromUser());
                }

            }
            catch (Exception ex)
            {
                var result = new JsonResult(new { error = "The server failed to process this file.  Please verify source data is compatible." });
                result.StatusCode = 500;
                return result;
            }

            return Json(new { thumbnail = "url" + ".jpg" });
        }
开发者ID:CatalystCode,项目名称:TerrainFlow-Web,代码行数:58,代码来源:ProjectsController.cs

示例5: UpdateLogoAsync

        public async Task<string> UpdateLogoAsync(string clubName, IFormFile file)
        {
            string path = clubName;

            var relativePath = path;
            if (string.IsNullOrEmpty(path) || !path.Contains(LogoPath))
            {
                var newName = (string.IsNullOrWhiteSpace(path) ? GenerateNewName() : path) + "." + file.FileName.Split('.').Last();
                var newPath = GenerateNewPath(LogoPath);
                relativePath = Path.Combine(newPath, newName);
                path = GetFullPath(relativePath);
            }
            else
            {
                path = GetFullPath(path);
            }

            await file.CopyToAsync(new FileStream(path, FileMode.Create));
            relativePath = Regex.Replace(relativePath, "\\\\", "/");

         //   await _clubService.UpdateLogoAsync(clubName, relativePath);
            
            return relativePath;
        }
开发者ID:parys,项目名称:MyLiverpool,代码行数:24,代码来源:UploadService.cs


注:本文中的IFormFile.CopyToAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。