Exemplo n.º 1
0
        public async Task <IActionResult> Index(IFormFile file)
        {
            FileViewModel viewModel = new FileViewModel();

            //Yüklenen dosyanın MemoryStream nesnesini oluşturalım
            MemoryStream stream = new MemoryStream();

            file.CopyTo(stream);
            stream.Position = 0;
            string objectName  = Guid.NewGuid().ToString().Substring(0, 7) + Path.GetExtension(file.FileName);
            string contentType = file.ContentType;

            try
            {
                //Bu isimde bir bucket olup olmadığını kontrol edelim.
                bool isFound = await _fileManager.BucketExistsAsync(_bucketName);

                if (!isFound)
                {
                    //Bu isimde bir bucket yoksa oluşturalım.
                    await _fileManager.MakeBucketAsync(_bucketName);
                }

                await _fileManager.PutObjectAsync(_bucketName, objectName, stream, stream.Length, contentType);

                viewModel.FileName = objectName;
            }
            catch (MinioException m)
            {
                viewModel.Message = m.message;
            }

            return(View(viewModel));
        }