【问题标题】:iOS/Objective-C Google Cloud Storage upload fileiOS/Objective-C 谷歌云存储上传文件
【发布时间】:2019-03-07 10:07:35
【问题描述】:

我正在尝试将谷歌云存储添加到 iOS 应用程序。我已经在 android 上玩过它,它工作正常。我没有很好地测试它,但它看起来不错。 然而,我搜索了很多,我没有找到任何接近我在 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 这样简单的东西。

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-10
      • 2019-06-09
      • 1970-01-01
      • 2018-06-16
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多