你如何在Bluemix中使用存储服务?

时间:2015-04-07 13:11:57

标签: ibm-cloud object-storage

我试图将一些存储数据插入Bluemix,我搜索了许多维基页面,但我无法得出结论如何继续。那么任何人都能告诉我如何通过任何语言代码(Java,Node.js)存储Bluemix存储中的图像和文件吗?

6 个答案:

答案 0 :(得分:3)

您可以使用多种方法在应用中存储文件。它们都不包括在应用程序容器文件系统中执行它,因为文件空间是临时的,并且每次创建应用程序的新实例时都将从Droplet重新创建。

您可以使用MongoLab,Cloudant,Object Storage和Redis等服务来存储所有类型的blob数据。

答案 1 :(得分:3)

假设您正在使用Bluemix编写Cloud Foundry应用程序,另一个选项是sshfs。在应用程序的启动时,您可以使用sshfs创建与作为本地目录挂载的远程服务器的连接。例如,您可以创建一个指向远程SSH服务器的./data目录,并为您的应用程序提供持久存储位置。

以下a blog post解释了此策略的工作原理,a source repo显示它曾用于在Cloud Foundry应用中托管Wordpress博客。

答案 2 :(得分:1)

请注意,正如其他人所建议的那样,存在许多用于存储对象数据的服务。转到Bluemix目录[1]并在左侧边距中选择“数据管理”。每个服务都应该有足够的文档来帮助您入门,包括许多示例应用程序和教程。只需单击服务磁贴,然后单击“查看文档”按钮即可找到相关文档。

[1] https://console.ng.bluemix.net/?ace_base=true/#/store/cloudOEPaneId=store

答案 3 :(得分:0)

结帐https://www.ng.bluemix.net/docs/#services/ObjectStorageV2/index.html#gettingstarted。 Bluemix中的存储服务是在Softlayer中运行的OpenStack Swift。查看此页面(http://docs.openstack.org/developer/swift/)了解Swift上的文档。

这是一个列出Swift的一些客户端的页面。 https://wiki.openstack.org/wiki/SDKs

答案 4 :(得分:0)

我搜索时有一个名为Object Storage服务的服务,也是由IBM创建的。但是,在momenti我无法在Bluemix目录中看到它。我想,他们还给了它,将来会发布新服务。

答案 5 :(得分:0)

请注意,bluemix中的pobject存储现在与S3兼容。所以例如你可以使用Boto或boto3(对于python人)它将100%API可以使用。 在这里看一些例子:https://ibm-public-cos.github.io/crs-docs/crs-python.html

此脚本可帮助您递归列出所有存储桶中的所有对象:

import boto3
endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'
s3 = boto3.resource('s3', endpoint_url=endpoint)
for bucket in s3.buckets.all():
    print(bucket.name)
    for obj in bucket.objects.all():
        print("  - %s") % obj.key

如果要指定凭据,则为:

import boto3
endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'
s3 = boto3.resource('s3', endpoint_url=endpoint, aws_access_key_id=YouRACCessKeyGeneratedOnYouBlueMixDAShBoard, aws_secret_access_key=TheSecretKeyThatCOmesWithYourAccessKey, use_ssl=True)

for bucket in s3.buckets.all():
    print(bucket.name)
    for obj in bucket.objects.all():
        print("  - %s") % obj.key

如果你想创建一个" hello.txt"将文件放入新存储桶中。 :

import boto3
endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'
s3 = boto3.resource('s3', endpoint_url=endpoint, aws_access_key_id=YouRACCessKeyGeneratedOnYouBlueMixDAShBoard, aws_secret_access_key=TheSecretKeyThatCOmesWithYourAccessKey, use_ssl=True)
my_bucket=s3.create_bucket('my-new-bucket')
s3.Object(my_bucket, 'hello.txt').put(Body=b"I'm a test file")

如果要在新存储桶中上传文件:

import boto3
endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'
s3 = boto3.resource('s3', endpoint_url=endpoint, aws_access_key_id=YouRACCessKeyGeneratedOnYouBlueMixDAShBoard, aws_secret_access_key=TheSecretKeyThatCOmesWithYourAccessKey, use_ssl=True)
my_bucket=s3.create_bucket('my-new-bucket')
timestampstr = str (timestamp)
s3.Bucket(my_bucket).upload_file(<location of yourfile>,<your file name>, ExtraArgs={ "ACL": "public-read", "Metadata": {"METADATA1": "resultat" ,"METADATA2": "1000","gid": "blabala000", "timestamp": timestampstr },},)