Esempio n. 1
0
        public ActionResult saveProfilePic()
        {
            if (Request.IsAuthenticated)
            {
                string s = Request["userId"];
                if (s == User.Identity.GetUserId())
                {
                    HttpPostedFileBase file = Request.Files[0];
                    string             id   = User.Identity.GetUserId();
                    var user = db.AspNetUsers.Find(id);

                    string         extension   = System.IO.Path.GetExtension(file.FileName);
                    string         newFileName = "p" + User.Identity.GetUserId() + extension;
                    AmazonS3Config config      = new AmazonS3Config();
                    config.ServiceURL = "https://s3.amazonaws.com/";
                    Amazon.S3.IAmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(_awsAccessKey, _awsSecretKey, config);

                    var request2 = new PutObjectRequest()
                    {
                        BucketName  = _bucketName,
                        CannedACL   = S3CannedACL.PublicRead, //PERMISSION TO FILE PUBLIC ACCESIBLE
                        Key         = _folderName + newFileName,
                        InputStream = file.InputStream        //SEND THE FILE STREAM
                    };
                    s3Client.PutObject(request2);
                    user.dpExtension = extension;
                    db.SaveChanges();
                }



                //for (int i = 0; i < Request.Files.Count; i++)
                //{
                //    string id = User.Identity.GetUserId();
                //    var user = db.AspNetUsers.Find(id);
                //    System.IO.File.Delete(Server.MapPath(@"~\Images\Users\p" + id + user.dpExtension));
                //    HttpPostedFileBase file = Request.Files[i];
                //    string extension = System.IO.Path.GetExtension(file.FileName);
                //    file.SaveAs(Server.MapPath(@"~\Images\Users\p" + User.Identity.GetUserId() + extension));
                //    user.dpExtension = extension;
                //    db.SaveChanges();
                //}
            }
            return(RedirectToAction("../User/Profile", new { id = User.Identity.GetUserId() }));
        }
 public AmazonContent(string bucketName, string keyName, long?size,
                      Amazon.S3.IAmazonS3 amazonS3,
                      IMultiPartUploadInfoFactory multiPartUploadInfoFactory,
                      IUploadIdentifierProvider uploadIdentifierProvider,
                      IContentNameProvider contentNameProvider,
                      IDownloadInfoFactory downloadInfoFactory,
                      IHttpPartUploadInfoFactory httpPartUploadInfoFactory)
 {
     _bucketName = bucketName;
     _keyName    = keyName;
     _size       = size;
     _amazonS3   = amazonS3;
     _multiPartUploadInfoFactory = multiPartUploadInfoFactory;
     _uploadIdentifierProvider   = uploadIdentifierProvider;
     _contentNameProvider        = contentNameProvider;
     _downloadInfoFactory        = downloadInfoFactory;
     _httpPartUploadInfoFactory  = httpPartUploadInfoFactory;
 }
Esempio n. 3
0
        public ActionResult uploadLogo()
        {
            int id = int.Parse(Request["id"]);
            HttpPostedFileBase file      = Request.Files["fileInput"];
            string             extension = System.IO.Path.GetExtension(file.FileName);



            string         newFileName = id + "/logo" + extension;
            AmazonS3Config config      = new AmazonS3Config();

            config.ServiceURL = "https://s3.amazonaws.com/";
            Amazon.S3.IAmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(_awsAccessKey, _awsSecretKey, config);

            var request2 = new PutObjectRequest()
            {
                BucketName  = _bucketName,
                CannedACL   = S3CannedACL.PublicRead, //PERMISSION TO FILE PUBLIC ACCESIBLE
                Key         = _folderName + newFileName,
                InputStream = file.InputStream        //SEND THE FILE STREAM
            };

            s3Client.PutObject(request2);
            var data = db.Companies.Find(id);

            data.logoextension   = extension;
            db.Entry(data).State = EntityState.Modified;
            db.SaveChanges();


            //string companyFolder = "~/Images/Company/" + id;
            //if (! System.IO.Directory.Exists(Server.MapPath(companyFolder)))
            //{
            //    System.IO.Directory.CreateDirectory(Server.MapPath(companyFolder));
            //}
            ////filename = "temp" + DateTime.UtcNow.Ticks + extension;
            //file.SaveAs(Server.MapPath(companyFolder + "/logo" + extension ));
            //var data = db.Companies.Find(id);
            //data.logoextension = extension;
            //db.Entry(data).State = EntityState.Modified;
            //db.SaveChanges();
            return(RedirectToAction("Details", "Company", new { id = id, title = ElectronicsController.URLFriendly(data.title) }));
        }
Esempio n. 4
0
 public S3Helper(bool isLocalDebug, string bucketName, string keyName)
 {
     this.IsLocalDebug = isLocalDebug;
     this.bucketName   = bucketName;
     this.keyName      = keyName;
     if (IsLocalDebug)
     {
         var            chain = new CredentialProfileStoreChain();
         AWSCredentials awsCredentials;
         if (chain.TryGetAWSCredentials(Constants.AWSProfileName, out awsCredentials))
         {
             // use awsCredentials
             S3Client = new AmazonS3Client(awsCredentials, Amazon.RegionEndpoint.USEast1);
         }
     }
     else
     {
         S3Client = new AmazonS3Client();
     }
 }
Esempio n. 5
0
 public LambdaFunctionTest()
 {
     Amazon.Runtime.AWSCredentials credentials = new Amazon.Runtime.StoredProfileAWSCredentials(profileName);
     s3Client = new AmazonS3Client(credentials, Amazon.RegionEndpoint.APSouth1);
 }