コード例 #1
0
        private async Task <UploadedFileData> UploadAsync(IFormFile file, string FolderPath)
        {
            string UniqueFileName = Guid.NewGuid() + file.FileName.Replace('/', '_');
            string fileFullPath   = $"{FolderPath}/{UniqueFileName}";

            using (var stream = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write)) {
                await file.CopyToAsync(stream);
            }
            var uploadFileData = new UploadedFileData {
                Path = fileFullPath,
                Url  = fileFullPath.Replace(BasePath, BaseUrl)
            };

            return(uploadFileData);
        }
コード例 #2
0
        public async Task <Response <bool> > Handle(UpdateUserPhotoCommand request, CancellationToken cancellationToken)
        {
            UploadedFileData uploadedData = await fileManager.AddFileAsync(request.Photo, FileTypeEnum.UserPhoto);

            Img userPhoto = await photoRepo.GetImgByUserIdAsync(request.Userid);

            // remove from hard
            fileManager.DeleteFile(userPhoto.Path);
            // remove from db
            await photoRepo.Remove(userPhoto);

            Img newImg = new Img {
                UserId = request.Userid,
                Url    = uploadedData.Url,
                Path   = uploadedData.Path
            };
            await photoRepo.AddAsync(newImg);

            return(Response.Ok());
        }