Ejemplo n.º 1
0
        public async Task <JsonResult> UploadImage(IFormFile file)
        {
            //TODO: localize exception messages

            if (file == null)
            {
                throw new UserFriendlyException("No file found!");
            }

            if (file.Length <= 0)
            {
                throw new UserFriendlyException("File is empty!");
            }

            if (!file.ContentType.Contains("image"))
            {
                throw new UserFriendlyException("Not a valid image!");
            }

            var output = await _fileAppService.CreateAsync(
                new FileUploadInputDto
            {
                Bytes = file.GetAllBytes(),
                Name  = file.FileName
            }
                );

            return(Json(new FileUploadResult(output.WebUrl)));
        }
Ejemplo n.º 2
0
 public async Task <BlobDto> UploadAsync([NotNull] string containerName, IFormFile File, string EntityType, string EntityId)
 {
     return(await _blobAppService.SaveAsync(containerName,
                                            new SaveBytesInput
     {
         Bytes = File.GetAllBytes(),
         EntityType = EntityType,
         EntityId = EntityId,
         FileName = File.FileName
     }));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 上传单个文件
        /// </summary>
        /// <param name="http_file"></param>
        /// <param name="save_path"></param>
        /// <returns></returns>
        public async Task <UploadFileModel> UploadSingleFile(IFormFile http_file, string save_path)
        {
            http_file.Should().NotBeNull();
            save_path.Should().NotBeNullOrEmpty();

            var bs        = http_file.GetAllBytes();
            var file_name = http_file.FileName;

            var res = await this.UploadSingleFile(bs, file_name, save_path);

            return(res);
        }
Ejemplo n.º 4
0
        public async Task <PopularResult <string> > FileUploadAsync([FromForm] IFormFile file)
        {
            var    result   = new PopularResult <string>();
            string filePath = _configuration["ImagePath"];

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            var fullPath  = Path.Combine(filePath, DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + Path.GetExtension(file.FileName));
            var imageFile = System.IO.File.Create(fullPath);
            await imageFile.WriteAsync(file.GetAllBytes());

            imageFile.Close();
            result.Success(Path.GetFileName(fullPath));
            return(await Task.FromResult(result));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> UploadFile(IFormFile file, [FromForm(Name = "ng-chat-participant-id")]
                                                     string userId)
        {
            // Storing file in temp path
            var filePath = Path.Combine(Path.GetTempPath(), file.FileName);

            if (file.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }
            }

            var baseUri = new Uri($"{Request.Scheme}://{Request.Host}{Request.PathBase}");

            var upyun = await GetUploader();

            var result = upyun.writeFile($"/somall/chat/{userId}/{file.FileName}", file.GetAllBytes(),
                                         true);

            if (result)
            {
                var path = $"{upyun.Domain}/somall/chat/{userId}/{file.FileName}";

                return(Ok(new
                {
                    type = 2, // MessageType.File = 2
                    //fromId: ngChatSenderUserId, fromId will be set by the angular component after receiving the http response
                    toId = userId,
                    message = file.FileName,
                    mimeType = file.ContentType,
                    fileSizeInBytes = file.Length,
                    downloadUrl = path
                }));
            }

            return(Ok(new
            {
                type = 1, // MessageType.File = 2
                //fromId: ngChatSenderUserId, fromId will be set by the angular component after receiving the http response
                toId = userId,
                message = "发送图片,但失败了",
            }));
        }
Ejemplo n.º 6
0
        public string UploadFiles(IFormFile layoutfile, string AlarmcBliudName)
        {
            string directorypath = AppContext.BaseDirectory + "AlarmFiles" + "\\" + AlarmcBliudName;

            try
            {
                var directory = FilesHelper.IsExistDirectory(directorypath);

                if (false == directory)
                {
                    FilesHelper.CreateDir(directorypath);
                }
                FilesHelper.CreateFile(directorypath + "\\" + layoutfile.FileName, layoutfile.GetAllBytes());
            }
            catch (Exception)
            {
                return("上传失败");
            }


            return("ok");
        }
Ejemplo n.º 7
0
        public async Task <string> UploadFiles(IFormFile layoutfile, IFormFile cameraDatafile, string projectName)
        {
            string directorypath = AppContext.BaseDirectory + "ProjectFiles" + "\\" + projectName;

            try
            {
                var directory = FilesHelper.IsExistDirectory(directorypath);

                if (false == directory)
                {
                    FilesHelper.CreateDir(directorypath);
                }
                FilesHelper.CreateFile(directorypath + "\\" + layoutfile.FileName, layoutfile.GetAllBytes());
                FilesHelper.CreateFile(directorypath + "\\" + cameraDatafile.FileName, cameraDatafile.GetAllBytes());
            }
            catch (Exception)
            {
                return("上传失败");
            }


            return("ok");
        }
Ejemplo n.º 8
0
        public async Task <JsonResult> UploadImage(IFormFile file)
        {
            //TODO: localize exception messages

            if (file == null)
            {
                throw new UserFriendlyException("No file found!");
            }

            if (file.Length <= 0)
            {
                throw new UserFriendlyException("File is empty!");
            }
            // TODO : @maliming ADD break point here
            var output = await _fileAppService.CreateAsync(
                new FileUploadInputDto
            {
                Bytes = file.GetAllBytes(),
                Name  = file.FileName
            }
                );

            return(Json(new FileUploadResult(output.WebUrl, output.Name)));
        }
Ejemplo n.º 9
0
        public JsonResult UploadFile(IFormFile file)
        {
            // TODO 限制文件大小
            if (file == null)
            {
                throw new UserFriendlyException("No file found!");
            }
            if (file.Length <= 0)
            {
                throw new UserFriendlyException("File is empty!");
            }

            var fileResult = _fileStoreManager.SaveFileAndGetResult(
                new FileInfo
            {
                Bytes    = file.GetAllBytes(),
                FileName = file.FileName,
                FileSize = file.Length,
                FileType = file.ContentType
            }
                );

            return(Json(fileResult));
        }