iOS/Objective-C Google Cloud Storage 上传文件

标签 ios objective-c rest google-cloud-platform google-cloud-storage

我正在尝试将谷歌云存储添加到 iOS 应用程序。我已经在安卓上玩过它并且运行得很好。我没有很好地测试它,但看起来不错。 然而,我搜索了很多,没有找到任何与我在 Android 上所做的类似的东西。

我找到了例子,但对于初学 iOS 开发者来说确实很困惑 https://github.com/google/google-api-objectivec-client-for-rest/blob/master/Examples/StorageSample/StorageSampleWindowController.m

在 Android 上我这样做了:

Credentials credentials;

InputStream iStream = context.getResources().openRawResource(R.raw.credential);
credentials = GoogleCredentials.fromStream(iStream);

Storage storage = StorageOptions.newBuilder().setCredentials(credentials).setProjectId(CommonSharedData.GCP_PROJECT).build().getService();
BlobId blobId = BlobId.of(CommonSharedData.GCP_BUCKET, CommonSharedData.MEDIA_DIR + "/" + fileName.getName());

BlobInfo blobInfo = null;
blobInfo = BlobInfo.newBuilder(blobId).setContentType(CommonSharedData.GCP_IMAGE_JPG).build();

byte[] stream = bytesArray(fileName);

Blob blob = storage.create(blobInfo, stream);
Acl acl = storage.createAcl(blobId, Acl.of(Acl.User.ofAllUsers(), Acl.Role.READER));

凭证文件结构:

{
  "type": "service_account",
  "project_id": "blablalbla",
  "private_key_id": "blablalbla",
  "private_key": "blablalbla",
  "client_email": "blablalbla",
  "client_id": "blablalbla",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "blablalbla"
}

但是我在 Objective C 上找不到像 iOS 那样简单的东西。

我只需要简单的工作示例。

最佳答案

我无法使用直接 API 在 iOS 上使用谷歌云。 我必须使用 firebase 作为图层。但他们有令人惊叹的代码。

关于iOS/Objective-C Google Cloud Storage 上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54862053/

相关文章:

IOS Objective C - 从 url 接收 json 数据时出错

ios - Sprite 套件侧滚动

ios - Objective-C对象设计模式

iphone - 在 iPhone 编程中寻找时间

java - 从 javascript 调用 java Restful Webservice 时返回值失败

ios - Cocoapods 错误 : unable to update after adding new Facebook iOS SDK

ios - 无法从 iCloud 照片库下载视频

ios - Objective C 新头文件标有灰色图标且无法导入框架

bash - curl: 没有为 restful api 指定 URL

java - 设计一个使用或不使用 Google App Engine 进行部署的应用程序