Пример #1
0
        private static string UploadFile(GStorage storage)
        {
            string fileName = "test.jpg";
            string bucket   = "xxxxx";
            string url      = "";

            using (var file = new FileStream(fileName, FileMode.Open))
            {
                file.Position = 0;
                storage.UploadFile(bucket, fileName, file, success => { url = success.PublicLink(); },
                                   null, Access.Public);
            }
            return(url);
        }
Пример #2
0
        private static GStorage WithServiceAccountAuthorization()
        {
            string clientIdService = "xxxxx.apps.googleusercontent.com";
            string serviceMail     = @"*****@*****.**";
            string project         = "xxxxx-748";
            string authFile        = "auth.p12";
            var    storage         = new GStorage(new GStorageParams
            {
                ClientId = clientIdService,
                Mail     = serviceMail,
                Project  = project
            });

            storage.ServiceAuthorize(authFile);
            return(storage);
        }
Пример #3
0
        private static GStorage WithOAuthAuthorization()
        {
            string clientId     = "xxxxx.apps.googleusercontent.com";
            string clientSecret = "xxxxx";
            string mail         = @"*****@*****.**";
            string project      = "xxxxx-748";

            var storage = new GStorage(new GStorageParams
            {
                ClientId     = clientId,
                ClientSecret = clientSecret,
                Mail         = mail,
                Project      = project
            });

            storage.Authorize();
            storage.RefreshAuthorization();
            return(storage);
        }
        public ActionResult AuthorizeOAuth()
        {
            string clientId     = "xxxxx.apps.googleusercontent.com";
            string clientSecret = "xxxxx";
            string mail         = @"*****@*****.**";
            string project      = "xxxxx-748";

            var storage = new GStorage(new GStorageParams
            {
                ClientId     = clientId,
                ClientSecret = clientSecret,
                Mail         = mail,
                Project      = project
            });

            var r = storage.AuthorizeWebAppBegin(_httpLocalhost);

            Session["storage"] = storage;
            return(Redirect(r));
        }
        public ActionResult UploadFileServiceAuthorization(HttpPostedFileBase file)
        {
            string clientIdService = "xxxxx.apps.googleusercontent.com";
            string serviceMail     = @"*****@*****.**";
            string project         = "xxxxx-748";
            string authFile        = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "auth.p12");

            var storage = new GStorage(new GStorageParams
            {
                ClientId = clientIdService,
                Mail     = serviceMail,
                Project  = project
            });

            storage.ServiceAuthorize(authFile);

            string fileName = "test.jpg";
            string bucket   = "xxxxx";
            string url      = "";

            storage.UploadFile(bucket, fileName, file.InputStream, success => { url = success.PublicLink(); });

            return(RedirectToAction("Success", "Home", new { url = url }));
        }