Exemplo n.º 1
0
        public async Task <IActionResult> Index([FromForm] string name, [FromForm] IFormFile file)
        {
            int userId = 0;

            if (!file.ContentType.Equals("video/mp4"))
            {
                ViewData["Message"] = "File not correct type mp4 files only";
                return(View());
            }

            userId = int.Parse(this.User.Claims.FirstOrDefault().Value);

            BucketAccess bucket = new BucketAccess();
            string       url    = await bucket.UpdateFile(file.FileName, file.ContentType, file.OpenReadStream());

            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();
                User  user  = context.Users.Find(userId);               //
                Video video = new Video
                {
                    Name      = name,
                    bucketurl = url,
                    User      = user,
                };
                context.Videos.Add(video);
                context.SaveChanges();
            }

            ViewData["Message"] = "File successfully uploaded upload another?";
            return(View());
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            BucketAccess bucket = new BucketAccess();

            using (var context = new DbSqlContext()){
                context.Database.EnsureCreated();
            }
            BuildWebHost(args).Run();
        }
Exemplo n.º 3
0
        public static TestConnectivityResult testConnectivity()
        {
            try
            {
                S3Service service = GetService();

                BucketAccess access = service.QueryBucket(Program.Config.BucketName);

                if (access.HasFlag(BucketAccess.NoSuchBucket))
                {
                    return(TestConnectivityResult.BUCKET_DOESNT_EXIST);
                }
                else if (access.HasFlag(BucketAccess.NotAccessible))
                {
                    return(TestConnectivityResult.INACCESSIBLE);
                }
                else if (access.HasFlag(BucketAccess.Accessible))
                {
                    return(TestConnectivityResult.OK);
                }
                else
                {
                    return(TestConnectivityResult.UNKNOWN);
                }
            }
            catch (S3Exception e)
            {
                switch (e.ErrorCode)
                {
                case S3ErrorCode.PermanentRedirect:
                    MessageBox.Show("You are accessing this bucket via the wrong region.");
                    break;

                case S3ErrorCode.InvalidAccessKeyId:
                case S3ErrorCode.SignatureDoesNotMatch:
                    MessageBox.Show("There was a problem using your credentials, please check them");
                    break;

                default:
                    MessageBox.Show("[" + e.ErrorCode + "]: " + e.Message);
                    break;
                }
                return(TestConnectivityResult.S3_EXCEPTION);
            }
            catch (Exception e)
            {
                return(TestConnectivityResult.EXCEPTION);
            }
        }