生成查询数据点的预签名URL
更新时间:2019-06-18
预签名URL可以用于前端页面查询数据点用法:前端请求服务器生成预签名url并返回给前端,前端使用该URL发起ajax请求查询数据点。
生成基于Query对象的预签名URL
timestamp = int(time.time()) #指定计算签名的时间戳
expiration_in_seconds = 1800 #指定url过期时间
per_signed_url = tsdb_client.generate_pre_signed_url(query_list,
timestamp=timestamp, expiration_in_seconds=expiration_in_seconds) #生成预签名的URL
print per_signed_url
返回结果:
http://databasename.tsdb.iot.bj.baidubce.com/v1/datapoint?authorization=bce-auth-v1%2Fa85ed2d7649141e08bf79fbbd88edc12%2F2018-07-23T10%3A06%3A46Z%2F1800%2F%2Fbe601040db0e5aa8f959248651b5ea7373c5d22fbece0d34eb21eb5cc8763f02&disablePresampling=False&query=%7B%22queries%22%3A%20%5B%5D%7D
生成基于SQL的预签名URL
可以参考如下代码:
sql = "select * from wind"
timestamp = int(time.time())
per_signed_url_sql = tsdb_client.generate_pre_signed_url_with_sql(sql,
timestamp=timestamp, expiration_in_seconds=1800)
print per_signed_url_sql
返回结果:
http://databasename.tsdb.iot.bj.baidubce.com/v1/row?authorization=bce-auth-v1%2Fa85ed2d7649141e08bf79fbbd88edc12%2F2018-07-23T10%3A26%3A33Z%2F1800%2F%2F73c721bff21300c17d8ec4e1fab94b6cbf91672c33417276808c534c85163b1d&sql=select%20%2A%20from%20wind