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); }
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 })); }