华为云用户手册

  • 响应消息 响应参数 返回状态码为 200: successful operation。 表2 响应Body参数列表 名称 类型 描述 vpn_connection ResponseVpnConnection object vpn_connection对象。 request_id String 请求ID。 表3 ResponseVpnConnection 名称 类型 描述 id String 功能说明:VPN连接ID。 格式:36位UUID。 name String 功能说明:VPN连接名称,不填时会自动生成。 取值范围:1-64个字符,支持数字、英文字母、中文(\u4e00 - \u9fa5)、_(下划线)、-(中划线)、.(点)。 status String 功能说明:VPN连接状态。 取值范围: ERROR:异常。 ACTIVE:正常。 DOWN:未连接。 PENDING_CREATE:创建中。 PENDING_UPDATE:更新中。 PENDING_DELETE:删除中。 FREEZED:冻结中。 UNKNOWN:未知。 vgw_id String 功能说明:VPN网关ID。 格式:36位UUID。 vgw_ip String 功能说明: VPN网关EIP的ID或接入私网IP。 格式:36位UUID或点分十进制IPv4地址(如192.168.45.7)。 style String 功能说明:连接模式。 取值范围: POLICY: 策略模式。 STATIC: 静态路由模式。 BGP: bgp路由模式。 POLICY-TEMPLATE: 策略模板模式。 cgw_id String 功能说明:对端网关ID。 格式:36位UUID。 peer_subnets Array of String 对端子网。当VPN网关的关联模式为ER并且style字段为BGP或POLICY时不返回。 tunnel_local_address String 路由模式下配置在VPN网关上的tunnel接口地址。仅当style为STATIC或BGP时有效。 tunnel_peer_address String 路由模式下配置在用户侧设备上的tunnel接口地址。仅当style为STATIC或BGP时有效。 enable_nqa Boolean 功能说明:开启NQA检测。仅当style为STATIC时返回。 取值范围:true,false。 policy_rules Array of PolicyRule objects 策略模式的策略规则组。仅当style为POLICY时返回实际的策略规则组。 ikepolicy IkePolicy object ike策略对象。 ipsecpolicy IpsecPolicy object ipsec策略对象。 created_at String 创建时间。 UTC时间格式:yyyy-MM-ddTHH:mm:ss。 非UTC时间格式:yyyy-MM-ddTHH:mm:ssZ。 updated_at String 最后一次更新时间。 UTC时间格式:yyyy-MM-ddTHH:mm:ss。 非UTC时间格式:yyyy-MM-ddTHH:mm:ssZ。 enterprise_project_id String 功能说明:企业项目ID。 格式:36位UUID。与vgw_id所标识VPN网关的企业项目ID一致。 connection_monitor_id String 功能说明:VPN连接监控ID。仅当VPN连接下创建有连接监控时返回。 格式:36位UUID。 ha_role String 功能说明:主备模式VPN网关下的连接时,'master'表示主连接,'slave'表示备连接。双活模式下的连接ha_role都是'master'。 默认值:master tags Array of VpnResourceTag objects 标签列表。 表4 PolicyRule 名称 类型 描述 rule_index Integer 功能说明:规则ID。 取值范围:0-50。 source String 源地址网段。 destination Array of String 目的地址网段。单个网段格式示例:192.168.52.0/24。每个PolicyRule最多返回50个。 表5 IkePolicy 名称 类型 描述 ike_version String 功能说明:IKE版本号。 取值范围:v1, v2。 phase1_negotiation_mode String 功能说明:协商模式。仅当IKE版本为v1时返回。 取值范围: main:主模式,协商过程安全性高。 aggressive:野蛮模式,协商快速且协商成功率高。 authentication_algorithm String 功能说明:认证算法。 取值范围:sha2-512,sha2-384,sha2-256,sha1,md5,sm3。 encryption_algorithm String 功能说明:加密算法。 取值范围:aes-256-gcm-16,aes-128-gcm-16,aes-256,aes-192,aes-128,3des,sm4。 dh_group String 功能说明:第一阶段密钥交换使用的DH组,当VPN网关flavor为GM时不返回。 取值范围:group1,group2,group5,group14,group15,group16,group19,group20,group21。 authentication_method String 功能说明:ike协商时的认证方法。 取值范围: pre-share:预共享密钥。 digital-envelope-v2:国密数字信封。 lifetime_seconds Integer 功能说明:表示SA的生存周期,当该生存周期超时后IKE SA将自动更新。 取值范围:60-604800,单位:秒。 local_id_type String 功能说明:本端ID类型,当VPN网关flavor为GM时不返回。 取值范围:ip,fqdn。 local_id String 本端ID。当local_id_type为ip时返回VPN连接所使用的网关IP;当local_id_type为fqdn时返回创建或更新VPN连接时指定的本端ID。 当VPN网关flavor为GM时不返回。 peer_id_type String 功能说明:对端ID类型,当VPN网关flavor为GM时不返回。 取值范围:ip,fqdn。 peer_id String 对端ID。当peer_id_type为ip时返回对端网关的IP;当peer_id_type为fqdn时返回创建或更新VPN连接时指定的对端ID。 当VPN网关flavor为GM时不返回。 dpd Dpd object 对等体存活检测对象。 表6 Dpd 名称 类型 描述 timeout Integer 功能说明:对等体存活检测报文重传间隔。 取值范围:2-60,单位:秒。 interval Integer 功能说明:对等体存活检测空闲时间。 取值范围:10-3600,单位:秒。 msg String 功能说明:对等体存活检测报文格式。 取值范围: seq-hash-notify:指定DPD报文中的载荷顺序是hash-notify。 seq-notify-hash:指定DPD报文中的载荷顺序是notify-hash。 表7 IpsecPolicy 名称 类型 描述 authentication_algorithm String 功能说明:认证算法。 取值范围:sha2-512,sha2-384,sha2-256,sha1,md5,sm3。 encryption_algorithm String 功能说明:加密算法。 取值范围:aes-256-gcm-16,aes-128-gcm-16,aes-256,aes-192,aes-128,3des,sm4。 pfs String 功能说明:PFS使用的DH密钥组,当VPN网关flavor为GM时不返回。 取值范围:group1,group2,group5,group14,group15,group16,group19,group20,group21,disable。 transform_protocol String 功能说明:传输协议。 取值范围: esp:封装安全协议。 lifetime_seconds Integer 功能说明:表示配置IPSec连接建立的隧道以时间为基准的生存周期。 取值范围:30-604800,单位:秒。 encapsulation_mode String 功能说明:报文封装模式。 取值范围: tunnel:隧道模式。 表8 VpnResourceTag 名称 类型 描述 key String 功能说明:标签的键。 取值范围:1-128个字符,支持数字、英文字母、中文、西班牙语、葡语、空格,以及以下字符:_.:=+-@。 value String 功能说明:标签的值。 取值范围:0-255个字符,支持数字、英文字母、中文、西班牙语、葡语、空格,以及以下字符:_.:=+-@。 响应样例 { "vpn_connection": { "id": "98c5af8a-demo-a8df-va86-ae2280a6f4c3", "name": "vpn-1655", "status": "DOWN", "vgw_id": "b32d91a4-demo-a8df-va86-e907174eb11d", "vgw_ip": "0c464dad-demo-a8df-va86-c22bb0eb0bde", "style": "POLICY", "cgw_id": "5247ae10-demo-a8df-va86-dd36659a7f5d", "peer_subnets": ["192.168.0.0/24"], "tunnel_local_address": "169.254.56.225/30", "tunnel_peer_address": "169.254.56.226/30", "policy_rules": [{ "rule_index": 1, "source": "10.0.0.0/24", "destination": [ "192.168.0.0/24" ] }], "ikepolicy": { "ike_version": "v2", "authentication_algorithm": "sha2-256", "encryption_algorithm": "aes-128", "dh_group": "group15", "authentication_method": "pre-share", "lifetime_seconds": 86400, "local_id_type": "ip", "local_id": "10.***.***.134", "peer_id_type": "ip", "peer_id": "88.***.***.164", "dpd": { "timeout": 15, "interval": 30, "msg": "seq-hash-notify" } }, "ipsecpolicy": { "authentication_algorithm": "sha2-256", "encryption_algorithm": "aes-128", "pfs": "group15", "transform_protocol": "esp", "lifetime_seconds": 3600, "encapsulation_mode": "tunnel" }, "created_at": "2022-11-26T13:41:34.626Z", "updated_at": "2022-11-26T13:41:34.626Z", "enterprise_project_id": "0", "ha_role":"master" }, "request_id": "f91082d4-6d49-479c-ad1d-4e552a9f5cae" }
  • 状态码 表1 正常返回值 正常返回码 类型 说明 200 OK GET、PUT操作正常返回。 201 Created POST操作正常返回。 204 No Content DELETE操作正常返回。 表2 异常返回值 返回值 类型 说明 400 Bad Request 服务器未能处理请求。 401 Unauthorized 被请求的页面需要用户名和密码。 403 Forbidden 对被请求页面的访问被禁止。 404 Not Found 服务器无法找到被请求的页面。 405 Method Not Allowed 请求中指定的方法不被允许。 406 Not Acceptable 服务器生成的响应无法被客户端所接受。 407 Proxy Authentication Required 用户必须首先使用代理服务器进行验证,这样请求才会被处理。 408 Request Timeout 请求超出了服务器的等待时间。 409 Conflict 由于冲突,请求无法被完成。 500 Internal Server Error 请求未完成。服务异常。 501 Not Implemented 请求未完成。服务器不支持所请求的功能。 502 Bad Gateway 请求未完成。服务器从上游服务器收到一个无效的响应。 503 Service Unavailable 请求未完成。系统暂时异常。 504 Gateway Timeout 网关超时。 父主题: 附录
  • 响应消息 响应参数 返回状态码为 200: successful operation。 表8 响应Body参数列表 名称 类型 描述 vpn_connection ResponseVpnConnection object vpn_connection对象。 request_id String 请求ID。 表9 ResponseVpnConnection 名称 类型 描述 id String 功能说明:VPN连接ID。 格式:36位UUID。 name String 功能说明:VPN连接名称,不填时会自动生成。 取值范围:1-64个字符,支持数字、英文字母、中文(\u4e00 - \u9fa5)、_(下划线)、-(中划线)。 vgw_id String 功能说明:VPN网关ID。 格式:36位UUID。 vgw_ip String 功能说明: VPN网关EIP的ID或接入私网IP。 格式:36位UUID或点分十进制IPv4地址(如192.168.45.7)。 style String 功能说明:连接模式。 取值范围: POLICY: 策略模式。 STATIC: 静态路由模式。 BGP: bgp路由模式。 POLICY-TEMPLATE: 策略模板模式。 cgw_id String 功能说明:对端网关ID。 格式:36位UUID。 peer_subnets Array of String 对端子网。当VPN网关的关联模式为ER并且style字段为BGP或POLICY时不返回。 tunnel_local_address String 路由模式下配置在VPN网关上的tunnel接口地址。仅当style为STATIC或BGP时有效。 tunnel_peer_address String 路由模式下配置在用户侧设备上的tunnel接口地址。仅当style为STATIC或BGP时有效。 enable_nqa Boolean 功能说明:开启NQA检测。仅当style为STATIC时返回。 取值范围:true,false。 policy_rules Array of PolicyRule objects 策略模式的策略规则组。仅当style为POLICY时返回实际的策略规则组。 ikepolicy IkePolicy object ike策略对象。 ipsecpolicy IpsecPolicy object ipsec策略对象。 created_at String 创建时间。 UTC时间格式:yyyy-MM-ddTHH:mm:ss。 非UTC时间格式:yyyy-MM-ddTHH:mm:ssZ。 updated_at String 最后一次更新时间。 UTC时间格式:yyyy-MM-ddTHH:mm:ss。 非UTC时间格式:yyyy-MM-ddTHH:mm:ssZ。 enterprise_project_id String 功能说明:企业项目ID。 格式:36位UUID。与vgw_id所标识VPN网关的企业项目ID一致。 connection_monitor_id String 功能说明:VPN连接监控ID。仅当VPN连接下创建有连接监控时返回。 格式:36位UUID。 ha_role String 功能说明:主备模式VPN网关下的连接时,'master'表示主连接,'slave'表示备连接。双活模式下的连接ha_role都是'master'。 默认值:master。 tags Array of VpnResourceTag objects 标签列表。 表10 PolicyRule 名称 类型 描述 rule_index Integer 功能说明:规则ID。 取值范围:0-50。 source String 源地址网段。 destination Array of String 目的地址网段。单个网段格式示例:192.168.52.0/24。每个PolicyRule最多返回50个。 表11 IkePolicy 名称 类型 描述 ike_version String 功能说明:IKE版本号。 取值范围:v1, v2。 phase1_negotiation_mode String 功能说明:协商模式。仅当IKE版本为v1时返回。 取值范围: main:主模式,协商过程安全性高。 aggressive:野蛮模式,协商快速且协商成功率高。 authentication_algorithm String 功能说明:认证算法。 取值范围:sha2-512,sha2-384,sha2-256,sha1,md5,sm3。 encryption_algorithm String 功能说明:加密算法。 取值范围:aes-256-gcm-16,aes-128-gcm-16,aes-256,aes-192,aes-128,3des,sm4。 dh_group String 功能说明:第一阶段密钥交换使用的DH组,当VPN网关flavor为GM时不返回。 取值范围:group1,group2,group5,group14,group15,group16,group19,group20,group21。 authentication_method String 功能说明:ike协商时的认证方法。 取值范围: pre-share:预共享密钥。 digital-envelope-v2:国密数字信封。 lifetime_seconds Integer 功能说明:表示SA的生存周期,当该生存周期超时后IKE SA将自动更新。 取值范围:60-604800,单位:秒。 local_id_type String 功能说明:本端ID类型,当VPN网关flavor为GM时不返回。 取值范围:ip,fqdn。 local_id String 本端ID。当local_id_type为ip时返回VPN连接所使用的网关IP;当local_id_type为fqdn时返回创建或更新VPN连接时指定的本端ID。 当VPN网关flavor为GM时不返回。 peer_id_type String 功能说明:对端ID类型,当VPN网关flavor为GM时不返回。 取值范围:ip,fqdn,any。 peer_id String 对端ID。当peer_id_type为ip时返回对端网关的IP;当peer_id_type为fqdn时返回创建或更新VPN连接时指定的对端ID;当peer_id_type为any时不返回。 当VPN网关flavor为GM时不返回。 dpd Dpd object 对等体存活检测对象。 表12 Dpd 名称 类型 描述 timeout Integer 功能说明:对等体存活检测报文重传间隔。 取值范围:2-60,单位:秒。 interval Integer 功能说明:对等体存活检测空闲时间。 取值范围:10-3600,单位:秒。 msg String 功能说明:对等体存活检测报文格式。 取值范围: seq-hash-notify:指定DPD报文中的载荷顺序是hash-notify。 seq-notify-hash:指定DPD报文中的载荷顺序是notify-hash。 表13 IpsecPolicy 名称 类型 描述 authentication_algorithm String 功能说明:认证算法。 取值范围:sha2-512,sha2-384,sha2-256,sha1,md5,sm3。 encryption_algorithm String 功能说明:加密算法。 取值范围:aes-256-gcm-16,aes-128-gcm-16,aes-256,aes-192,aes-128,3des,sm4。 pfs String 功能说明:PFS使用的DH密钥组 取值范围:group1,group2,group5,group14,group15,group16,group19,group20,group21,disable。 transform_protocol String 功能说明:传输协议。 取值范围: esp:封装安全协议。 lifetime_seconds Integer 功能说明:表示配置IPSec连接建立的隧道以时间为基准的生存周期。 取值范围:30-604800,单位:秒。 encapsulation_mode String 功能说明:报文封装模式。 取值范围: tunnel:隧道模式。 表14 VpnResourceTag 名称 类型 描述 key String 功能说明:标签的键。 取值范围:1-128个字符,支持数字、英文字母、中文、西班牙语、葡语、空格,以及以下字符:_.:=+-@。 value String 功能说明:标签的值。 取值范围:0-255个字符,支持数字、英文字母、中文、西班牙语、葡语、空格,以及以下字符:_.:=+-@。 响应样例 更新VPN连接的响应。 { "vpn_connection": { "id": "98c5af8a-demo-a8df-va86-ae2280a6f4c3", "name": "vpn-1655", "vgw_id": "b32d91a4-demo-a8df-va86-e907174eb11d", "vgw_ip": "0c464dad-demo-a8df-va86-c22bb0eb0bde", "style": "POLICY", "cgw_id": "5247ae10-demo-a8df-va86-dd36659a7f5d", "peer_subnets": ["192.168.1.0/24"], "tunnel_local_address": "169.254.56.225/30", "tunnel_peer_address": "169.254.56.226/30", "policy_rules": [{ "rule_index": 1, "source": "10.0.0.0/24", "destination": [ "192.168.1.0/24" ] }], "ikepolicy": { "ike_version": "v2", "authentication_algorithm": "sha2-256", "encryption_algorithm": "aes-128", "dh_group": "group15", "authentication_method": "pre-share", "lifetime_seconds": 86400, "local_id_type": "ip", "local_id": "10.***.***.134", "peer_id_type": "ip", "peer_id": "88.***.***.164", "dpd": { "timeout": 15, "interval": 30, "msg": "seq-hash-notify" } }, "ipsecpolicy": { "authentication_algorithm": "sha2-256", "encryption_algorithm": "aes-128", "pfs": "group15", "transform_protocol": "esp", "lifetime_seconds": 3600, "encapsulation_mode": "tunnel" }, "created_at": "2022-11-26T13:41:34.626Z", "updated_at": "2022-11-26T13:41:34.626Z", "enterprise_project_id": "0", "ha_role": "master" }, "request_id": "f91082d4-6d49-479c-ad1d-4e552a9f5cae" } 冻结场景下更新失败。 { "error_code": "VPN.0001", "error_msg": "invalid request: ILLEGAL not allowed update vpnConnection", "request_id": "8c833634-4560-7897-7740-a7462f5bcbd4" }
  • 响应消息 响应参数 返回状态码为 200: 查询成功。 表2 响应Body参数列表 名称 类型 描述 customer_gateway ResponseCustomerGateway object customer_gateway对象。 request_id String 请求id。 表3 ResponseCustomerGateway 名称 类型 描述 id String 功能说明:对端网关的ID。 格式:36位UUID。 name String 功能说明:对端网关名称,不填时会自动生成。 取值范围:1-64个字符,支持数字、英文字母、中文(\u4e00 - \u9fa5)、_(下划线)、-(中划线)、.(点)。 id_type String 功能说明:对端网关标识类型。 取值范围:ip,fqdn。 id_value String 对端网关标识值。 bgp_asn Long 对端网关的BGP自治域编号。仅当id_type为ip时返回。 ca_certificate CaCertificate object 对端网关CA证书信息。仅当对端网关绑定CA证书时返回。 created_at String 创建时间。 UTC时间格式:yyyy-MM-ddTHH:mm:ss。 非UTC时间格式:yyyy-MM-ddTHH:mm:ssZ。 updated_at String 最后一次更新时间。 UTC时间格式:yyyy-MM-ddTHH:mm:ss。 非UTC时间格式:yyyy-MM-ddTHH:mm:ssZ。 tags Array of VpnResourceTag objects 标签列表。 表4 CaCertificate 名称 类型 描述 id String 证书ID。 serial_number String 证书序列号。 signature_algorithm String 签名算法。 issuer String 证书颁发者。 subject String 证书使用者。 expire_time String 证书过期时间。 is_updatable boolean 是否能更新证书内容。 表5 VpnResourceTag 名称 类型 描述 key String 功能说明:标签的键。 取值范围:1-128个字符,支持数字、英文字母、中文、西班牙语、葡语、空格,以及以下字符:_.:=+-@。 value String 功能说明:标签的值。 取值范围:0-255个字符,支持数字、英文字母、中文、西班牙语、葡语、空格,以及以下字符:_.:=+-@。 响应样例 { "customer_gateway": { "id": "03c0aa3d-demo-a8df-va86-9d82473765d4", "name": "cgw-ba08", "id_type": "ip", "id_value": "10.***.***.21", "bgp_asn": 65000, "ca_certificate": { "serial_number": "14257156674311863338", "signature_algorithm": "SM3WITHSM2", "issuer": "C=CN,O=a0002,CN=XXX", "subject": "C=CN,O=a0002,CN=XXX", "expire_time": "2024-05-22T07:34:22Z", "is_updatable": true }, "created_at": "2021-12-21T16:49:28.108+08:00", "updated_at": "2021-12-21T16:49:28.108+08:00" }, "request_id": "8111d315-5024-45c9-8ee3-5ef676edb0d1" }
  • [Version Changes] Please carefully read the changes made to the Privacy Statement due to service development and optimization: Added the Shimo Docs function. Added the description of third-party services (mainly Shimo Docs) and added the personal information obtained from Shimo Docs to the personal information obtained from third parties in the section "How We Collect Your Personal Data." Added the third-party service provider Shimo Docs to the section "Third-Party Service Providers and Their Services." Added the transfer and virtual background functions of HarmonyOS. Added the description of personal information involved in HarmonyOS transfer and virtual background functions to the section "How We Collect Your Personal Data." Added the permission description for the HarmonyOS transfer function to section "Required Permissions." Added the 360 virtual background SDK of Qiku Software (Shenzhen) Co., Ltd. to the section "Third-Party Service Providers and Their Services." Removed the HiCar function. Added the description of bringing the HiCar function offline to sections "Required Permissions" and "Third-Party Service Providers and Their Services." Updated: July 27, 2022 View Huawei Cloud Meeting Privacy Statement
  • The following describes changes of earlier versions. [Version Changes] We have updated the Privacy Statement to improve your experience with this service. Please read the following to learn more about the relevant changes. Added the SmartRooms and IdeaHub access scenarios. Added the description of Personal Data collection, permissions, and path of disabling automatic collection in SmartRooms and IdeaHub access scenarios in Article "How We Collect Your Personal Data." Added the description of third-party SDKs in Article "Third-Party Service Providers and Their Services." Added the user experience improvement program. Added the description of joining and exiting the user experience improvement program in Article "How We Use Your Personal Data." Adjusted the report retention period for better public environment. Changed the report retention period from 30 days to 6 months in Section "Data Storage and Retention." Updated: June 1, 2022 View Huawei Cloud Meeting Privacy Statement
  • 以下为历史版本变更说明 版本变更说明 Meeting新增支持OPPO/VIVO手机推送会议通知功能,为此更新隐私声明。 “第三方SDK”章节中,新增OPUSH SDK、VIVO推送SDK。 “个人信息存储期限”章节中,增加推送功能个人数据留存期描述。 更新时间:2024年1月12日 点击查看华为云会议隐私声明全文 版本变更说明 因业务发展优化导致隐私声明更新,请您仔细阅读此次隐私声明的变更内容: Meeting新增支持企业微信用户快速登录华为云会议,新增电话权限适配Android 12系统,为此更新隐私声明。 “您提供的个人信息”章节中,新增1.2.2 企业微信登录功能相关描述及涉及的个人数据说明、新增1.2.5 音视频会议服务,含网络研讨会中电话权限、自启动相关描述。 “设备权限调用”章节中,新增Android系统电话权限描述、iOS系统本地网络权限描述。 “第三方SDK”章节中,新增企业微信登录分享SDK、统一扫描服务SDK。 更新时间:2024年1月5日 点击查看华为云会议隐私声明全文 版本变更说明 因业务发展优化导致隐私声明更新,请您仔细阅读此次隐私声明的变更内容: Meeting新增屏蔽周围人声功能,为此更新隐私声明。 “您提供的个人信息”章节中,新增1.2.13 屏蔽周围人声功能相关描述及涉及的个人数据说明。 “我们如何对个人信息进行存储”章节中,新增屏蔽周围人声涉及的个人数据留存期说明。 增加距离传感器、方向传感器、系统信息、运营商信息、Wi-Fi信息收集场景和使用说明。 优化隐私声明部分段落语言描述方式,以更为清晰和便于您理解的方式,向您展示我们如何收集和使用您的个人数据。 更新时间:2023年7月11日 点击查看华为云会议隐私声明全文 版本变更说明 因业务发展优化导致隐私声明更新,请您仔细阅读此次隐私声明的变更内容: Meeting服务新增支持石墨文档的功能,为此隐私更新 “我们收集和使用哪些信息”章节中,新增以石墨为代表的第三方服务相关描述,从第三方获取的个人信息中增加从石墨获取的个人数据 “第三方服务提供商及其服务”章节中,新增第三方供应商石墨 Meeting服务新增鸿蒙流转、虚拟背景功能,为此隐私更新 “我们收集和使用哪些信息”章节中,新增鸿蒙流转、虚拟背景中涉及的个人数据说明 “设备权限调用”章节中,新增鸿蒙流转使用的权限说明 “第三方服务提供商及其服务”章节中,新增360虚拟背景SDK(奇酷软件(深圳)有限公司) Meeting服务HiCar场景功能下线,为此隐私更新 “设备权限调用”章节、“第三方服务提供商及其服务”章节中,增加hicar场景功能下线说明 更新时间:2022年7月27日 点击查看华为云会议隐私声明全文 版本变更说明 因业务发展优化导致隐私声明更新,请您仔细阅读此次隐私声明的变更内容: 华为云会议服务新增SmartRooms、IdeaHub系列接入场景,为此更新隐私声明 “我们收集和使用哪些信息”章节中,新增SmartRooms、IdeaHub系列接入场景个人数据收集说明、权限使用场景说明、关闭自动收集路径的描述 “第三方服务提供商及其服务”章节中,新增第三方SDK说明 华为云会议服务新增用户体验改进计划,为此更新隐私声明 “我们如何使用您的个人信息”章节中,新增用户体验改进计划加入和退出的描述 华为云会议服务加强公共环境管理,调整了举报的留存期,为此更新隐私声明 “数据存储与保留”章节,举报留存期从30天调整到6个月 更新时间:2022年6月1日 点击查看华为云会议隐私声明全文
  • 标注数据.json文件说明 数据集中必含“.json”文件,用于集合该时间戳已标注点云的所有标注数据信息,包括该点云所在的项目id、数据包id、图片上所有标注框信息等。上传数据集前请保证“.json”文件内容正确。“.json”文件编写的参考样例如下: 3D立方体框数据: 该文件说明适用于3D目标识别,3D目标追踪,3D联合任务。 { "frame_id": 11, #帧序号 "batch_task_id": 2284, #批次任务ID "project_id": "da7febfd1405496ffd1240e6c17efc0f", #资源域ID "label_mode": "auto", #标注类型:auto和manual两种 "status": " labeled ", #标注任务状态:unlabeled、labeled "sample_type": "POINT_CLOUD", #样本类型:包含”IMAGE”(图片)和” POINT_CLOUD”(点云) "des_order": "", #此份数据对应的原始数据包描述 "tag_names": [ "a_in_premodel", "b_in_premodel" ], #标签名称 "valid": true, #是否有效,包含”true”和”false”两种 "create_time": 1669339994173, #标注的创建时间 "difficult": false, #是否难例,包含”true”难例和”false”非难例 "label_counts": [ #各类标注物的个数统计 { "label_meta_id": 5414, #标注物使用的标签ID, "label_num": 1, #标注物个数 "label_meta_name": "Car", #标签名称 "label_meta_desc": "自采目标识别", #标签描述 "label_meta_attr": "{\"优先级\":\"0,1\"}", #标签额外属性 "label_meta_shape": "cube_3d", #标签形状 "label_meta_color": "#d0021b", #标签颜色 "level": 0 } ], "point_cloud_meta_info": { #3D点云的标注属性信息,包含标定项id、图片名称、传感器类型、图片大小、图片源的obs路径url、时间戳 "id": "6a275591-53e1-406e-820e-ad077ae1da49", "name": "lidar-269-19.pcd", #点云名称 "source":"https://Octopus-raw-da7febfd1405496ffd1240e6c17efc0f.obs.cn-north-5.myhuaweicloud.com/label-data/task-2284/data/8/lidar-269-19.pcd", #点云源的obs路径url "calibration_item_id": 269, #标定项ID "sensor": "lidar", #传感器类型 "timestamp": 1669339994173, "size": 0 }, "image_meta_infos": [ #图片属性信息,包含标定项id、图片名称、传感器类型、图片大小、图片源的obs路径url、时间戳 { "id": "3b018a08-caa8-4e86-ae7a-1e9988b65578", "name": "camera03-268-19.jpg", "source": "https://Octopus-raw-da7febfd1405496ffd1240e6c17efc0f.obs.cn-north-5.myhuaweicloud.com/label-data/task-2284/data/8/camera03-268-19.jpg", "sensor": "camera03_0", #传感器名称 "timestamp": 1669339994173, "calibration_item_id": 268, #标定项ID "size": { #图片尺寸 "width": 1920, "depth": 3, "height": 1020 } } ], "label_task_id": 1372, #批次子任务ID "partitionId": 20221124, "label_update_time": 1688457112216, #标注最近更新时间 "prefix_folder": "8", "image_id": "9af1a414-d943-4965-96dd-ac0cd620eda5", "inspection": 0, "labels": [ #标注物信息 { "label_meta_id": 5414, #标注物对应的标签ID "create_time": 0, "name": "Car", #标注物名称 "shape_type": "cube_3d", #标注物形状:3D立体框 "serial_number": 0, "label_object_id": -1, "attribute": "", #标注物属性 "label_meta_name": "Car", "inspection": { #审核属性 "miss_label_error": false, #漏标 "vehicle_direction_error": false, #车头方向错误 "attribute_error": false, #属性错误 "out_range_label_error": false, #未贴合 "anchor_error": false, #锚点错误 "classification_error": false, #类别错误 "correct_label": true, "extra_label_error": false #多标 }, "cube_3d": { "orientation": 1.53980839, "alpha": 1.527701791334979, "rotation": { #3D框旋转角 "x": 0.0, "y": 0.0, "z": 1.53980839 }, "bndboxs": [ #3D联合标注中2D框的标注信息 { "label_meta_id": 5414, "bndbox": { "ymin": 508.54608, "xmin": 926.8102, "ymax": 727.8024, "xmax": 1189.3324 }, "label_meta_color": "#d0021b", "serial_number": 2, "sensor": "camera03_0", "attribute": "{}", "source": "https://Octopus-raw-da7febfd1405496ffd1240e6c17efc0f.obs.cn-north-5.myhuaweicloud.com/label-data/task-2284/data/8/camera03-268-19.jpg", "label_meta_name": "Car", "inspection": { "miss_label_error": false, "vehicle_direction_error": false, "attribute_error": false, "out_range_label_error": false, "anchor_error": false, "classification_error": false, "correct_label": true, "extra_label_error": false } } ], "serial_number": 2, #标注物合成对象的唯一自增id,如果标注物之间没有合成则与serial_number保持一致,追踪任务中同一物体在不同帧中此字段相同 "location": { #3D框中心点坐标 "x": 0.6671804785728455, "y": 15.472203254699707, "z": -1.1619998216629028 }, "attribute": "{\"优先级\":\"1\"}", "dimensions": { #3D框长宽高 "length": 4.557755470275879, "width": 2.0348410606384277, "height": 1.4403225183486938 } } } ], "labels_ext": { "track_points": [ { "serial_number": 1, "points": [ ] } ] } }
  • 回放仿真作业队列相关操作 在“作业队列”页签,还可以进行以下操作。 表1 作业队列相关操作 任务 操作步骤 置顶作业 单击操作栏中的“置顶”,即可将作业调整至队列中最高优先级。 置底作业 单击操作栏中的“置底”,即可将作业调整至队列中最低优先级。 上移作业 单击操作栏中的“上移”,即可将作业调整至队列中上一级。 下移作业 单击操作栏中的“下移”,即可将作业调整至队列中下一级。 更新作业优先级 勾选单个或多个作业。 单击“更新优先级”,输入[-50,50]的整数,数字越大,优先级越高。 单击“确定”,优先级更改成功。相同优先级的任务,作业队列更新时间越早,优先级越高。 搜索作业 在搜索输入框中输入“作业ID”,按回车键即可查询。
  • 作业输入输出规范 用户完成自定义脱敏算子创建,运行作业容器时Octopus平台向其中注入以下环境变量: input_file:待脱敏的文件路径 raw_dir:抽取的image,gnss,lidar数据存放路径 desensitized_dir:脱敏后的image,gnss,lidar数据存放路径 output_dir:脱敏后的文件存放路径 用户根据需要可以自定义环境变量,以rosbag文件为例,可以定义如下环境变量: rosbag_version:robag版本 image_topics:图像数据topic列表 gnss_topic:gnss数据topic lidar_topics:lidar数据topic列表 用户作业容器需要将input_file中的image,gnss,lidar数据抽取到raw_dir,待系统内置算子脱敏完成,并将脱敏后的数据存放到desensitized_dir后,用户算子根据input_file和desensitized_dir中的脱敏数据生成新的数据文件存放到output_dir。 文件结构如下: -raw --image ---topic0 ----timestamp1.jpg ----timestamp2.jpg ---topic1 ----timestamp1.jpg --gnss ---gnss_topic.json --lidar ---pcd_topic0 ----timestamp0.pcd ----timestamp1.pcd --SUCCESS -desensitized --image ---topic0 ----timestamp1.jpg ----timestamp2.jpg ---topic1 ----timestamp1.jpg --gnss ---gnss_topic.json --lidar ---pcd_topic0 ----timestamp0.pcd ----timestamp1.pcd --SUCCESS -output --test.bag --SUCCESS 其中,“SUCCESS”文件为标识文件,标识所在阶段的任务结束。 父主题: 数据脱敏作业
  • 本地调试 准备一个待处理的rosbag包。 sudo docker run -v ${HOME}/data/test.bag:/home/main/test.bag --env input_file=/home/main/test.bag –env raw_dir=/home/main/raw_dir –env desensitized_dir=/home/main/desensitized_dir –env output_dir=/home/main/output_dir -it rosbagmask:0.1 /bin/sh -c "python mask.py"
  • 示例代码 用户可以自定义一个脱敏算子,构建为一个合规脱敏镜像,在Octopus平台镜像仓库中导入自己构建的合规脱敏镜像。在合规服务新建算子时,选择镜像仓库中自己导入的合规脱敏镜像,即可使用脱敏算子对数据进行脱敏处理。 下面是rosbag脱敏的算子示例: # mask.py import json import logging import multiprocessing as mp import os import shutil import time from pathlib import Path from typing import cast import av import numpy as np import open3d from rosbags.highlevel import AnyReader from rosbags.interfaces import ConnectionExtRosbag1, ConnectionExtRosbag2 from rosbags.rosbag1 import Writer as Writer1 from rosbags.rosbag2 import Writer as Writer2 from rosbags.serde import cdr_to_ros1, serialize_cdr from rosbags.typesys import get_types_from_msg, register_types from rosbags.typesys.types import builtin_interfaces__msg__Time as Time from rosbags.typesys.types import \ sensor_msgs__msg__CompressedImage as CompressedImage from rosbags.typesys.types import std_msgs__msg__Header as Header logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', ) LOG = logging.getLogger(__file__) # Octopus数据服务拉起镜像时灌入的环境变量 # 获取环境变量 input_path = os.getenv('input_path', 'data/hangyan-move.bag.bak') raw_dir = os.getenv('raw_dir', 'empty_dir/raw') # 抽取的文件存放目录 desens_dir = os.getenv('desensitized_dir', 'empty_dir/desens') # 脱敏后的文件存放目录 output_dir = os.getenv('output_dir', 'empty_dir/output') lidar_process_num = os.getenv('lidar_process_num', 5) # lidar数据进程数 # 用户自定义环境变量 rosbag_version = os.getenv('rosbag_version', '1') # rosbag版本,取值为'1'或'2' image_topics = [ x.strip(' ') for x in os.getenv('image_topics', '/camera_encoded_1').split(',') ] # 图像数据的topic列表 gnss_topic = os.getenv('gnss_topic', '/inspvax') # gnss数据的topic,gnss数据只能有一个topic lidar_topics = [ x.strip(' ') for x in os.getenv('lidar_topic', '/pandar').split(',') ] # 点云数据的topic列表 # 注册自定义消息类型 Video_encoded_data_text = Path('msgs/Video_encoded_data.msg').read_text() NovatelMessageHeader_text = Path('msgs/NovatelMessageHeader.msg').read_text() NovatelExtendedSolutionStatus_text = Path( 'msgs/NovatelExtendedSolutionStatus.msg').read_text() NovatelReceiverStatus_text = Path('msgs/NovatelReceiverStatus.msg').read_text() Inspvax_text = Path('msgs/Inspvax.msg').read_text() add_types = {} add_types.update( get_types_from_msg( Video_encoded_data_text, 'kyber_msgs/msg/Video_encoded_data', )) add_types.update( get_types_from_msg( NovatelMessageHeader_text, 'novatel_gps_msgs/msg/NovatelMessageHeader', )) add_types.update( get_types_from_msg( NovatelExtendedSolutionStatus_text, 'novatel_gps_msgs/msg/NovatelExtendedSolutionStatus', )) add_types.update( get_types_from_msg( NovatelReceiverStatus_text, 'novatel_gps_msgs/msg/NovatelReceiverStatus', )) add_types.update( get_types_from_msg( Inspvax_text, 'novatel_gps_msgs/msg/Inspvax', )) register_types(add_types) # create gnss file gnss_file_path = Path(raw_dir, 'gnss') / f'{gnss_topic}.json'.strip('/') Path.mkdir(gnss_file_path.parent, parents=True, exist_ok=True) def extract_image(input_rosbag): '''从原始rosbag中抽取图像数据.''' LOG.info('Start extracting image.') codec_ctx = av.codec.Codec('hevc', 'r') h265_code = codec_ctx.create() with AnyReader([Path(input_rosbag)]) as reader: for connection, timestamp, data in reader.messages(): topic = connection.topic if topic in image_topics: deserialized_data = reader.deserialize(data, connection.msgtype) try: data = deserialized_data.raw_data packet = av.packet.Packet(data) out = h265_code.decode(packet) img = None for frame in out: if frame.format.name != 'rgb24': frame = frame.reformat(format='rgb24') img = frame.to_image() # 图像存放路径 file_name = f'{timestamp}.jpg' f_path = Path(raw_dir, 'image') / topic.strip('/') tmp_path = Path(raw_dir, 'tmp_image') / topic.strip('/') Path.mkdir(tmp_path, parents=True, exist_ok=True) tmp_file = tmp_path / file_name file = f_path / file_name # 当未建立目录时,先基于topic名称建立目录 Path.mkdir(file.parent, parents=True, exist_ok=True) img.save(tmp_file) os.chmod(tmp_file, 0o777) os.chmod(file.parent, 0o777) shutil.move(tmp_file, file) except Exception as e: LOG.info("%s frame can not trans to jpg, message: %s", timestamp, str(e)) LOG.info('Finish extracting image.') def extract_lidar(task_id, task_num, input_rosbag): '''从原始rosbag中抽取点云数据.''' LOG.info('Start extracting pcd.') with AnyReader([Path(input_rosbag)]) as reader: for i, (connection, timestamp, data) in enumerate(reader.messages()): if i % task_num != task_id: continue topic = connection.topic if topic in lidar_topics: deserialized_data = reader.deserialize(data, connection.msgtype) pcd = open3d.geometry.PointCloud() reshaped = deserialized_data.data.reshape( int(len(deserialized_data.data) / 3), 3) pcd.points = open3d.utility.Vector3dVector(reshaped) file_name = f'{timestamp}.pcd' f_path = Path(raw_dir, 'lidar') / topic.strip('/') tmp_path = Path(raw_dir, 'tmp_lidar') / topic.strip('/') Path.mkdir(tmp_path, parents=True, exist_ok=True) tmp_file = tmp_path / file_name file = f_path / file_name # 当未建立目录时,先基于topic名称建立目录 Path.mkdir(file.parent, parents=True, exist_ok=True) open3d.io.write_point_cloud(str(tmp_file), pcd) os.chmod(tmp_file, 0o777) os.chmod(file.parent, 0o777) shutil.move(tmp_file, file) LOG.info('Finish extracting pcd.') def extract_gnss(input_rosbag): '''从原始rosbag中抽取gnss数据.''' LOG.info('Start extracting rosbag.') gnss_file = open(gnss_file_path, 'w') gnss = dict() with AnyReader([Path(input_rosbag)]) as reader: for connection, timestamp, data in reader.messages(): topic = connection.topic if topic == gnss_topic: deserialized_data = reader.deserialize(data, connection.msgtype) # 这里以msgytpe为NavSatFix为例 latitude = deserialized_data.latitude longitude = deserialized_data.longitude altitude = deserialized_data.altitude gnss[timestamp] = { 'latitude': latitude, 'longitude': longitude, 'altitude': altitude } gnss_file.write(json.dumps(gnss)) gnss_file.close() LOG.info('Finish extracting gnss.') def _get_masked_image(topic, timestamp): '''从脱敏后的图像数据中获取目标图像数据.''' file = Path(desens_dir, 'image') / topic.strip('/') / f'{timestamp}.jpg' if file.is_file(): return np.fromfile(file, dtype='uint8') else: return None def _get_conn_map(rosbag_version: int, reader, writer): '''构建connection的索引.''' conn_map = {} if rosbag_version == '1': for conn in reader.connections: if conn.topic in image_topics: conn_map[conn.id] = writer.add_connection( '/image', CompressedImage.__msgtype__, ) else: ext = cast(ConnectionExtRosbag1, conn.ext) conn_map[conn.id] = writer.add_connection( conn.topic, conn.msgtype, conn.msgdef, conn.md5sum, ext.callerid, ext.latching, ) elif rosbag_version == '2': for conn in reader.connections: if conn.topic in image_topics: conn_map[conn.id] = writer.add_connection( '/image', CompressedImage.__msgtype__, ) else: ext = cast(ConnectionExtRosbag2, conn.ext) conn_map[conn.id] = writer.add_connection( conn.topic, conn.msgtype, ext.serialization_format, ext.offered_qos_profiles, ) return conn_map def _serialize_data(rosbag_version, data, msgtype): '''对数据进行序列化.''' if rosbag_version == '1': return cdr_to_ros1(serialize_cdr(data, msgtype), msgtype) elif rosbag_version == '2': return serialize_cdr(data, msgtype) def generate_rosbag(input_rosbag, output_rosbag): '''生成脱敏后rosbag.''' LOG.info('Start generating rosbag.') gnss_file = open( Path(desens_dir, 'gnss') / f'{gnss_topic}.json'.strip('/'), 'r') gnss_data = json.load(gnss_file) gnss_file.close() Writer = Writer1 if rosbag_version == '1' else Writer2 with AnyReader([Path(input_rosbag) ]) as reader, Writer(Path(output_rosbag)) as writer: conn_map = _get_conn_map(rosbag_version, reader, writer) for connection, timestamp, data in reader.messages(): topic = connection.topic # 当topic为图像数据的topic时,读取脱敏后图像数据 if topic in image_topics: masked_data = _get_masked_image(topic, timestamp) if masked_data is None: # 没有解析出图像文件时,不要该帧了 continue deserialized_data = CompressedImage( Header( stamp=Time( sec=int(timestamp // 10**9), nanosec=int(timestamp % 10**9), ), frame_id='0', ), format='jpg', data=masked_data, ) data = _serialize_data( rosbag_version, deserialized_data, CompressedImage.__msgtype__, ) # 当topic为gnss数据时,读取脱敏后gnss数据 elif topic == gnss_topic: deserialized_data = reader.deserialize(data, connection.msgtype) deserialized_data.latitude = gnss_data.get( str(timestamp)).get('latitude') deserialized_data.longitude = gnss_data.get( str(timestamp)).get('longitude') deserialized_data.altitude = gnss_data.get( str(timestamp)).get('altitude') data = _serialize_data( rosbag_version, deserialized_data, connection.msgtype, ) # 当topic为点云数据时,读取脱敏后点云数据 elif topic in lidar_topics: deserialized_data = reader.deserialize( data, connection.msgtype, ) file = Path( desens_dir, 'lidar', ) / topic.strip('/') / f'{timestamp}.pcd' point_cloud = open3d.io.read_point_cloud(str(file)) deserialized_data.data = np.asarray( point_cloud.points).flatten() writer.write(conn_map[connection.id], timestamp, data) # 生成_SUCCESS文件标识完成数据抽取 Path(output_dir, '_SUCCESS').touch() LOG.info('Finish generating rosbag.') if __name__ == "__main__": LOG.info('Start user operator.') process_image = mp.Process(target=extract_image, args=(input_path, )) pool_lidar = mp.Pool(processes=lidar_process_num) for i in range(lidar_process_num): pool_lidar.apply_async(extract_lidar, args=(i, lidar_process_num, input_path)) process_gnss = mp.Process(target=extract_gnss, args=(input_path, )) # 启动子进程 process_image.start() pool_lidar.close() process_gnss.start() process_image.join() pool_lidar.join() process_gnss.join() LOG.info('Child processes exit.') # 生成_SUCCESS文件标识完成数据抽取 Path(raw_dir, '_SUCCESS').touch() # 后面输出的rosbag文件与输入的rosbag文件保持同名 output_rosbag_file = Path(output_dir, Path(input_path).name) # 如果输出文件夹不存在,先创建文件夹 Path.mkdir(output_rosbag_file.parent, parents=True, exist_ok=True) # 检测到脱敏任务结束后,生成新的rosbag文件 while time.sleep(1) is None: if Path(desens_dir).joinpath('_SUCCESS').is_file(): generate_rosbag(Path(input_path), output_rosbag_file) break 父主题: 数据脱敏作业
  • 接口约束 您必须是桶拥有者或拥有上传对象的权限,才能上传对象。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:object:PutObject权限,如果使用桶策略则需授予PutObject权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、配置对象策略。 OBS支持的region以及region与endPoint的对应关系,详细信息请参见地区与终端节点。 每次追加上传的长度不能超过单次上传长度上限5G的限制。 每个Appendable对象追加写次数最多为10000次,如果对象追加写次数超过10000次,OBS返回409 Conflict,错误码为ObjectNotAppendable。 如果对象存储类别为COLD(归档存储),则不能调用该接口。 如果桶设置了跨区域复制配置,则不能调用该接口。 并行文件系统不支持追加写对象。 ObsClient.putObject上传的对象可覆盖ObsClient.appendObject上传的对象,覆盖后对象变为普通对象,不可再进行追加上传。 对已有对象进行追加上传,要求对象必须为可追加上传的对象,否则将抛出异常(HTTP状态码为409)。判断对象是否可追加上传可通过获取对象元数据查询。
  • 功能说明 您可以根据需要上传文件或者文件夹至已有的OBS桶。待上传的文件可以是任何类型:文本文件、图片、视频等。 追加对象可以实现在桶中指定的对象尾直接追加上传数据,不存在相同名称的对象则创建新对象。每次追加上传都会更新该对象的最后修改时间。 每次追加上传成功后,可通过AppendObjectResult.getNextPosition获取下次追加上传的位置;或者通过ObsClient.getObjectMetadata接口获取下次追加上传的位置。
  • 代码示例 本示例用于通过设置每次追加上传的不同位置将数据内容追加上传到examplebucket桶下同一个objectname对象中。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.AppendObjectRequest; import com.obs.services.model.AppendObjectResult; import com.obs.services.model.ObjectMetadata; import java.io.ByteArrayInputStream; public class AppendObject001 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try (ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint)) { // 第一次追加上传 AppendObjectRequest request = new AppendObjectRequest(); request.setBucketName("examplebucket"); request.setObjectKey("objectname"); request.setPosition(0); request.setInput(new ByteArrayInputStream("Hello OBS".getBytes())); AppendObjectResult result = obsClient.appendObject(request); // 第二次追加上传 request.setPosition(result.getNextPosition()); request.setInput(new ByteArrayInputStream("Hello OBS Again".getBytes())); result = obsClient.appendObject(request); System.out.println("appendObject successfully"); System.out.println("NextPosition:" + result.getNextPosition()); System.out.println("Etag:" + result.getEtag()); // 通过获取对象属性接口获取下次追加上传的位置 ObjectMetadata metadata = obsClient.getObjectMetadata("examplebucket", "objectname"); System.out.println("NextPosition from metadata:" + metadata.getNextPosition()); } catch (ObsException e) { System.out.println("appendObject failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("appendObject failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 bucketName String 必选 参数解释: 桶名。 约束限制: 桶的名字需全局唯一,不能与已有的任何桶名称重复,包括其他用户创建的桶。 桶命名规则如下: 3~63个字符,数字或字母开头,支持小写字母、数字、“-”、“.”。 禁止使用IP地址。 禁止以“-”或“.”开头及结尾。 禁止两个“.”相邻(如:“my..bucket”)。 禁止“.”和“-”相邻(如:“my-.bucket”和“my.-bucket”)。 同一用户在同一个区域多次创建同名桶不会报错,创建的桶属性以第一次请求为准。 默认取值: 无 acl AccessControlList 必选 参数解释: 创桶时可指定桶的ACL访问策略,您可以使用预定义的ACL策略,也可以自定义ACL策略,有关访问控制列表(Access Control List,ACL)功能的详细信息可参见ACL功能介绍。 取值范围: 如果使用预定义ACL策略,则可选策略参见ACL预定义访问策略。 如果选择自定义ACL策略,则可以根据AccessControlList参数描述,自行给参数赋值。 默认取值: AccessControlList.REST_CANNED_PRIVATE
  • 代码示例:为桶设置预定义访问策略 本示例用于为exampleBucket桶设置预定义访问策略。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.AccessControlList; public class SetBucketAcl002 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { //示例桶名 String exampleBucket = "examplebucket"; // 设置桶访问权限为私有读写 obsClient.setBucketAcl(exampleBucket, AccessControlList.REST_CANNED_PRIVATE); System.out.println("SetBucketAcl successfully"); } catch (ObsException e) { System.out.println("SetBucketAcl failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("SetBucketAcl failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 代码示例:设置桶的访问策略 本示例用于直接设置exampleBucket桶的访问策略。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.AccessControlList; import com.obs.services.model.CanonicalGrantee; import com.obs.services.model.GroupGrantee; import com.obs.services.model.Owner; import com.obs.services.model.Permission; public class SetBucketAcl003 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { //示例桶名 String exampleBucket = "examplebucket"; //示例userid String exampleUserid = "userid"; //示例userid String exampleOwnerId = "ownerid"; AccessControlList acl = new AccessControlList(); Owner owner = new Owner(); owner.setId(exampleOwnerId); acl.setOwner(owner); // 为指定用户设置完全控制权限 acl.grantPermission(new CanonicalGrantee(exampleUserid), Permission.PERMISSION_FULL_CONTROL); // 为所有用户设置读权限 acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ); // 直接设置桶访问权限 obsClient.setBucketAcl(exampleBucket, acl); System.out.println("SetBucketAcl successfully"); } catch (ObsException e) { System.out.println("SetBucketAcl failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("SetBucketAcl failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 接口约束 单个桶最多支持100条ACL策略。 您必须是桶拥有者或拥有设置桶ACL的权限,才能设置桶ACL。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:bucket:PutBucketAcl权限,如果使用桶策略则需授予PutBucketAcl权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、自定义创建桶策略。 OBS支持的region以及region与endPoint的对应关系,详细信息请参见地区与终端节点。
  • 功能说明 OBS支持对桶操作进行权限控制,您可以为桶设置访问策略,指定某一个用户对某一个桶是否有权行使某一项指定操作。OBS权限控制的方式有IAM、桶策略和ACL三种,ACL按照粒度又分为桶ACL和对象ACL,本节将对桶ACL接口进行详细介绍,更多权限相关内容可参见《对象存储服务权限配置指南》的OBS权限控制概述章节。 桶ACL是跨账号场景的权限,设置授权的对象不是当前账号,也不是当前账号下的IAM用户,而是另一个云账号及其账号下的IAM用户;授权的范围是以桶为粒度的,一条ACL策略为一个桶设置策略,因此设置ACL策略时您必须明确指定桶名;桶ACL授予的权限包括桶的访问权限和桶ACL的访问权限两个方面,桶的访问权限包括对桶及桶内对象的查看和编辑权限,桶ACL的访问权限包括对桶ACL策略的查看和编辑权限,详情可参见ACL权限控制方式介绍。
  • 方法定义 方法1:创建桶时,设置访问权限: obsBucket.setBucketName(exampleBucket); // 设置桶访问权限为私有读写 obsBucket.setAcl(AccessControlList.REST_CANNED_PRIVATE); // 创建桶 obsClient.createBucket(obsBucket); 方法2:通过预定义访问策略设置访问权限: // 设置桶访问权限为私有读写 obsClient.setBucketAcl(String exampleBucket, AccessControlList.REST_CANNED_PRIVATE); 方法3:调用ObsClient.setBucketAcl直接设置访问权限: // 直接设置桶访问权限 obsClient.setBucketAcl(String bucketName,AccessControlList acl);
  • 接口约束 您必须是桶拥有者或拥有上传对象的权限,才能上传对象。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:object:PutObject权限,如果使用桶策略则需授予PutObject权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、配置对象策略。 OBS支持的region以及region与endPoint的对应关系,详细信息请参见地区与终端节点。 单次上传对象大小范围是[0, 5GB]。 如果需要上传超过5GB的大文件,需要通过分段上传来分段上传。
  • 代码示例 文件上传使用本地文件作为对象的数据源。以下代码展示了将本地文件localfile上传到examplebucket桶中。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.PutObjectRequest; import java.io.File; public class PutObject004 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { // 文件上传 // localfile 为待上传的本地文件路径,需要指定到具体的文件名 PutObjectRequest request = new PutObjectRequest(); request.setBucketName("examplebucket"); request.setObjectKey("objectkey"); request.setFile(new File("localfile")); obsClient.putObject(request); System.out.println("putObject successfully"); } catch (ObsException e) { System.out.println("putObject failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("putObject failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 request TruncateObjectRequest 必选 参数解释: 截断对象请求参数,详见TruncateObjectRequest。 表2 TruncateObjectRequest 参数名称 参数类型 是否可选 描述 bucketName String 必选 参数解释: 桶名。 约束限制: 桶的名字需全局唯一,不能与已有的任何桶名称重复,包括其他用户创建的桶。 桶命名规则如下: 3~63个字符,数字或字母开头,支持小写字母、数字、“-”、“.”。 禁止使用IP地址。 禁止以“-”或“.”开头及结尾。 禁止两个“.”相邻(如:“my..bucket”)。 禁止“.”和“-”相邻(如:“my-.bucket”和“my.-bucket”)。 同一用户在同一个区域多次创建同名桶不会报错,创建的桶属性以第一次请求为准。 默认取值: 无 objectKey String 必选 参数解释: 文件对象名。对象名是对象在存储桶中的唯一标识。对象名是对象在桶中的完整路径,路径中不包含桶名。 例如,您对象的访问地址为examplebucket.obs.cn-north-4.myhuaweicloud.com/folder/test.txt 中,对象名为folder/test.txt。 取值范围: 长度大于0且不超过1024的字符串。 默认取值: 无 newLength long 必选 参数解释: 文件截断后的大小。 默认取值: 无
  • 接口约束 您必须是并行文件系统拥有者或拥有截断对象的权限,才能截断对象。建议使用IAM或策略进行授权,如果使用IAM则需授予obs:bucket:PutObject权限,如果使用策略则需授予PutObject权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、配置对象策略。 OBS支持的region以及region与endPoint的对应关系,详细信息请参见地区与终端节点。 目前接口仅在并行文件系统支持,普通对象并行文件系统不支持,如何创建并行文件系统请参考创建并行文件系统(Java SDK)。
  • 代码示例 本示例用于将examplebucket并行文件系统中的objectname对象截断到指定大小,大小指定为1024L。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.TruncateObjectRequest; import com.obs.services.model.TruncateObjectResult; public class TruncateObject001 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { // 截断操作 TruncateObjectRequest request = new TruncateObjectRequest(); request.setBucketName("examplebucket"); request.setObjectKey("objectname"); request.setNewLength(1024L); TruncateObjectResult result = obsClient.truncateObject(request); System.out.println("truncateObject successfully"); System.out.println("HTTP Code: " + result.getStatusCode()); } catch (ObsException e) { System.out.println("truncateObject failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("truncateObject failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 代码示例:直接设置对象访问权限 以下代码展示如何将examplebucket桶下的objectname对象直接设置对象访问权限: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.AccessControlList; import com.obs.services.model.CanonicalGrantee; import com.obs.services.model.GroupGrantee; import com.obs.services.model.Owner; import com.obs.services.model.Permission; public class SetObjectAcl002 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { AccessControlList acl = new AccessControlList(); Owner owner = new Owner(); owner.setId("ownerid"); // 租户id,必填 acl.setOwner(owner); // 保留Owner的完全控制权限(注:如果不设置该权限,该对象Owner自身将没有访问权限) acl.grantPermission(new CanonicalGrantee("ownerid"), Permission.PERMISSION_FULL_CONTROL); // 为指定用户设置完全控制权限 acl.grantPermission(new CanonicalGrantee("userid"), Permission.PERMISSION_FULL_CONTROL); // 为所有用户设置读权限 acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ); obsClient.setObjectAcl("examplebucket", "objectname", acl); System.out.println("setObjectAcl successfully"); System.out.println(acl); } catch (ObsException e) { System.out.println("setObjectAcl failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("setObjectAcl failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 代码示例:为对象设置预定义访问策略 以下代码展示如何将examplebucket桶下的objectname对象通过预定义访问策略设置访问权限为私有读写: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.AccessControlList; public class SetObjectAcl001 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { // 为对象设置预定义访问策略 // 设置对象访问权限为私有读写 obsClient.setObjectAcl("examplebucket", "objectname", AccessControlList.REST_CANNED_PRIVATE); System.out.println("setObjectAcl successfully"); } catch (ObsException e) { System.out.println("setObjectAcl failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("setObjectAcl failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 代码示例:上传对象时指定预定义访问策略 以下代码展示如何将本地文件localfile上传到examplebucket桶下的objectname对象,同时指定预定义访问策略: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 import com.obs.services.ObsClient; import com.obs.services.exception.ObsException; import com.obs.services.model.AccessControlList; import com.obs.services.model.PutObjectRequest; import java.io.File; public class PutObject012 { public static void main(String[] args) { // 您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入。如果使用硬编码可能会存在泄露风险。 // 您可以登录访问管理控制台获取访问密钥AK/SK String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。 // 您可以通过环境变量获取访问密钥AK/SK/SecurityToken,也可以使用其他外部引入方式传入。 // String securityToken = System.getenv("SECURITY_TOKEN"); // endpoint填写桶所在的endpoint, 此处以华北-北京四为例,其他地区请按实际情况填写。 String endPoint = "https://obs.cn-north-4.myhuaweicloud.com"; // 您可以通过环境变量获取endPoint,也可以使用其他外部引入方式传入。 //String endPoint = System.getenv("ENDPOINT"); // 创建ObsClient实例 // 使用永久AK/SK初始化客户端 ObsClient obsClient = new ObsClient(ak, sk,endPoint); // 使用临时AK/SK和SecurityToken初始化客户端 // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); try { // 上传对象时指定预定义访问策略 PutObjectRequest request = new PutObjectRequest(); request.setBucketName("examplebucket"); request.setObjectKey("objectname"); request.setFile(new File("localfile")); // 设置对象访问权限为私有读写 request.setAcl(AccessControlList.REST_CANNED_PRIVATE); obsClient.putObject(request); System.out.println("putObject successfully"); } catch (ObsException e) { System.out.println("putObject failed"); // 请求失败,打印http状态码 System.out.println("HTTP Code:" + e.getResponseCode()); // 请求失败,打印服务端错误码 System.out.println("Error Code:" + e.getErrorCode()); // 请求失败,打印详细错误信息 System.out.println("Error Message:" + e.getErrorMessage()); // 请求失败,打印请求id System.out.println("Request ID:" + e.getErrorRequestId()); System.out.println("Host ID:" + e.getErrorHostId()); e.printStackTrace(); } catch (Exception e) { System.out.println("putObject failed"); // 其他异常信息打印 e.printStackTrace(); } } }
  • 请求参数说明 表1 请求参数列表 参数名称 参数类型 是否必选 描述 request SetObjectAclRequest 必选 参数解释: 设置对象ACL请求参数,详见表2。 表2 SetObjectAclRequest 参数名称 参数类型 是否必选 描述 bucketName String 必选 参数解释: 桶名。 约束限制: 桶的名字需全局唯一,不能与已有的任何桶名称重复,包括其他用户创建的桶。 桶命名规则如下: 3~63个字符,数字或字母开头,支持小写字母、数字、“-”、“.”。 禁止使用IP地址。 禁止以“-”或“.”开头及结尾。 禁止两个“.”相邻(如:“my..bucket”)。 禁止“.”和“-”相邻(如:“my-.bucket”和“my.-bucket”)。 同一用户在同一个区域多次创建同名桶不会报错,创建的桶属性以第一次请求为准。 默认取值: 无 objectKey String 必选 参数解释: 对象名。对象名是对象在存储桶中的唯一标识。对象名是对象在桶中的完整路径,路径中不包含桶名。 例如,您对象的访问地址为examplebucket.obs.cn-north-4.myhuaweicloud.com/folder/test.txt 中,对象名为folder/test.txt。 取值范围: 长度大于0且不超过1024的字符串。 默认取值: 无 versionId String 可选 参数解释: 对象的版本号。 取值范围: 长度为32的字符串。 默认取值: 无 acl AccessControlList 必选 参数解释: 指定对象的ACL访问策略,您可以使用预定义的ACL策略,也可以自定义ACL策略,有关访问控制列表(Access Control List,ACL)功能的详细信息可参见ACL功能介绍。 取值范围: 如果使用预定义ACL策略,则可选策略参见ACL预定义访问策略。 如果选择自定义ACL策略,则可以根据AccessControlList参数描述,自行给参数赋值。 默认取值: AccessControlList.REST_CANNED_PRIVATE
共100000条