Google 云存储命名空间
Google cloud storage namespace
我正在尝试将文件上传到我的存储空间。我用这个代码
String serviceAccountEmail = "YOUR SERVICE EMAIL HERE";
var certificate = new X509Certificate2(@"PATH TO YOUR p12 FILE HERE", "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 = "YOUR APPLICATION NAME HERE",
});
var fileobj = new Google.Apis.Storage.v1.Data.Object()
{
Bucket = "YOUR BUCKET NAME HERE",
Name = "file"
};
Stream stream = null;
stream = new MemoryStream(img);
Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload insmedia;
insmedia = new Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload(ss, fileobj, "YOUR BUCKET NAME HERE", stream, "image/jpeg");
insmedia.Upload();
我创建了一个新项目 -> 控制台应用程序 (C#),我认为引用有问题,因为我遇到了这些错误:
The type or namespace name 'Storage' does not exist in the namespace 'Google.Apis' (are you missing an assembly reference?)
我的使用:
using Google.Apis.Auth.OAuth2;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
我做错了什么?请帮助我:)
您似乎缺少 NuGet 包 - 您应该在项目中安装 Google.Apis.Storage.v1
package。之后,您应该可以添加
的 using
指令
using Google.Apis.Storage.v1;
...并使用代码:
var insmedia = new ObjectsResource.InsertMediaUpload(ss, fileobj,
"YOUR BUCKET NAME HERE", stream, "image/jpeg");
insmedia.Upload();
(当然是在设置桶名之后。)
我正在尝试将文件上传到我的存储空间。我用这个代码
String serviceAccountEmail = "YOUR SERVICE EMAIL HERE";
var certificate = new X509Certificate2(@"PATH TO YOUR p12 FILE HERE", "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 = "YOUR APPLICATION NAME HERE",
});
var fileobj = new Google.Apis.Storage.v1.Data.Object()
{
Bucket = "YOUR BUCKET NAME HERE",
Name = "file"
};
Stream stream = null;
stream = new MemoryStream(img);
Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload insmedia;
insmedia = new Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload(ss, fileobj, "YOUR BUCKET NAME HERE", stream, "image/jpeg");
insmedia.Upload();
我创建了一个新项目 -> 控制台应用程序 (C#),我认为引用有问题,因为我遇到了这些错误:
The type or namespace name 'Storage' does not exist in the namespace 'Google.Apis' (are you missing an assembly reference?)
我的使用:
using Google.Apis.Auth.OAuth2;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
我做错了什么?请帮助我:)
您似乎缺少 NuGet 包 - 您应该在项目中安装 Google.Apis.Storage.v1
package。之后,您应该可以添加
using
指令
using Google.Apis.Storage.v1;
...并使用代码:
var insmedia = new ObjectsResource.InsertMediaUpload(ss, fileobj,
"YOUR BUCKET NAME HERE", stream, "image/jpeg");
insmedia.Upload();
(当然是在设置桶名之后。)