void mediaDOwnloader(UserCredential credential) { //https://developers.google.com/api-client-library/dotnet/guide/media_download#sample-code // Create the service using the client credentials. //var driveService = new Google.Apis.Drive.v2.DriveService(); var storageService = new Google.Apis.Storage.v1.StorageService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "APP_NAME_HERE" }); // Get the client request object for the bucket and desired object. var getRequest = storageService.Objects.Get("BUCKET_HERE", "OBJECT_HERE"); using (var fileStream = new System.IO.FileStream( "FILE_PATH_HERE", System.IO.FileMode.Create, System.IO.FileAccess.Write)) { // Add a handler which will be notified on progress changes. // It will notify on each chunk download and when the // download is completed or failed. getRequest.MediaDownloader.ProgressChanged += (Google.Apis.Download.IDownloadProgress obj) => { };; getRequest.Download(fileStream); } }
public Bucket(string bucketId, CloudAuthenticator authenticator, StorageConfiguration configuration) { this._bucketId = bucketId; this._authenticator = authenticator; this._config = configuration; _authenticator.GetInitializer().GZipEnabled = _config.EnableGzip; _googleStorageService = new Google.Apis.Storage.v1.StorageService(_authenticator.GetInitializer()); }
public Bucket(string bucketId, CloudAuthenticator authenticator, StorageConfiguration configuration) { this._bucketId = bucketId; this._authenticator = authenticator; this._config = configuration; _authenticator.GetInitializer().GZipEnabled = _config.EnableGzip; _googleStorageService = new Google.Apis.Storage.v1.StorageService(_authenticator.GetInitializer()); }
public Google.Apis.Storage.v1.Data.Objects ListBucketContents(Google.Apis.Storage.v1.StorageService storage, string bucket) { //https://cloud.google.com/docs/authentication#code_samples var request = new Google.Apis.Storage.v1.ObjectsResource.ListRequest(storage, bucket); var requestResult = request.Execute(); return(requestResult); }
public void create_storage() { var service = new Google.Apis.Storage.v1.StorageService(); }
private void sendPicture(string userName, string photoName) { String serviceAccountEmail = "*****@*****.**"; string filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data/MyFirstProject-db5185b5746d.p12"); var certificate = new X509Certificate2(filePath, "notasecret", X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { Scopes = new[] { Google.Apis.Storage.v1.StorageService.Scope.DevstorageFullControl } }.FromCertificate(certificate)); Google.Apis.Storage.v1.StorageService ss = new Google.Apis.Storage.v1.StorageService(new Google.Apis.Services.BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "My First Project", }); var fileobj = new Google.Apis.Storage.v1.Data.Object() { Bucket = "keepguarantee", Name = userName + "/" + photoName }; //FileStream fileStream = null; //var dir = Directory.GetCurrentDirectory(); //var path = Path.Combine(dir, "test.png"); //fileStream = new FileStream(path, FileMode.Open); //var insmedia = new ObjectsResource.InsertMediaUpload(ss, fileobj, "keepguarantee", fileStream, "image/jpeg"); //insmedia.Upload(); }