[英]Temporary Public URL for IBM Bluemix Object Storage Service with NodeJs
[英]Public URLs For Objects In Bluemix Object Storage Service
我想将许多照片上传到Bluemix Object Storage服务,然后将其显示在Web应用程序中。 现在,对对象存储容器中的照片的GET请求需要和auth令牌。 有没有什么办法可以创建一个公共URL到对象,不需要GET请求的身份验证令牌?
我看到有一个选项可以创建对象的临时URL,但我不希望URL是临时的,我希望它永远存在。 是创建长期临时URL的唯一选择吗?
正确的方法是修改容器ACL。 您目前无法通过Bluemix UI执行此操作,但您可以使用Swift REST API 。 例如,要更改容器ACL以便任何人都可以读取容器中的对象,您可以发出以下PUT
请求。
curl -X PUT "https://dal.objectstorage.open.softlayer.com/v1/AUTH_123/mycontainer" \
-H "X-Auth-Token: token123" \
-H "X-Container-Read: .r:*"
我知道这是一个老帖子,但在IBM的Ryan Baxter和Object存储文档的帮助下我可以解决问题最后这些命令也节省了一天
首先使用swift并更改容器的访问控制
swift post container-name --read-acl ".r:*,.rlistings"
Next使用Curl将Container配置为特定Url以访问Files
curl -X GET " https://<access point>/<version>/AUTH_projectID/container-name" -H "X-Auth-Token:<auth token>" -H "X-Container-Read: .r:*,.rlistings"
并且非常感谢Alex da Silva提供的帮助
现在,BlueMix具有S3端点功能。 你可以使用curl或任何其他语言作为例子,这是一个boto3,它将上传一个对象,公开它和一些元数据:(该函数使用一个json文件,你存储凭据,它使用3个变量使用在全局应用程序中:currentdirpath,ImagesToS3,ImageName)
def UploadImageDansBucket (currentdirpath,ImagesToS3,ImageName) :
currentdirpath = 'path/to/your/dir/current'
ImagesToS3 = ' /path/of/your/object/'
ImageName = 'Objectname'
with open("credentials.json", 'r') as f:
data = json.loads(f.read())
bucket_target = data["aws"]["targetBucket"]
print ('Open Connection to the bucket in the cloud..........')
s3ressource = boto3.resource(
service_name='s3',
endpoint_url= data["aws"]["hostEndPoint"],
aws_access_key_id= data["aws"]["idKey"],
aws_secret_access_key=data["aws"]["secretKey"],
use_ssl=True,
)
s3ressource.meta.client.meta.events.unregister('before-sign.s3', fix_s3_host)
s3ressource.Object(bucket_target, 'hello.txt').put(Body=b"I'm a test file")
s3ressource.Object(bucket_target, 'bin.txt').put(Body=b"0123456789abcdef"*10000)
fn = "%s%s" % (ImagesToS3,ImageName)
data = open(fn, 'rb')
#s3ressource.Bucket(bucket_target).put_object(Key=fn, Body=data)
now = datetime.datetime.now() # on recupere la date actuelle
timestamp = time.mktime(now.timetuple()) # on effectue la convertion
timestampstr = str (timestamp)
s3ressource.Bucket(bucket_target).upload_file(fn,ImageName, ExtraArgs={ "ACL": "public-read", "Metadata": {"METADATA1": "a" ,"METADATA2": "b","METADATA3": "c", "timestamp": timestampstr },},)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.