gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:59:03 26 4
gpt4 key购买 nike

我正在尝试将谷歌云存储添加到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com