C SDK

<p class="shortdesc"></p> <section class="section" id="C_SDK___section_p4z_s5m_qlb"><h2 class="doc-tairway">1. 简介</h2> <ul class="ul" id="C_SDK___ul_hc2_rs4_qlb"> <li class="li">本文档主要介绍 OBS C SDK 的接口使用及注意事项;</li> <li class="li">并且假设您已经开通了 OBS 服务,并已是平安公有云用户;</li> <li class="li">如果您还没有开通或者还不了解平安公有云OBS服务,请登录<a class="xref" href="/ssr/products/OBS" target="_blank">平安云主页</a>进行了解。</li> <li class="li">OBS-C-SDK 是由平安云团队开发的工具包。便于开发者在 C语言环境下方便使用平安云当中的 OBS 服务。</li> <li class="li">文档主要罗列了OBS-C-SDK中,上传、下载以及删除的一些基本方法,并对方法参数进行简要解释,且对响应方法有一个详细的说明。</li> </ul> </section> <section class="section" id="C_SDK___section_dwc_t5m_qlb"><h2 class="doc-tairway">2. SDK下载</h2> <p class="p">C SDK 开发包最新版本 <a class="xref" href="https://pcp-obs.obs-cn-shanghai.pinganyun.com/obs-c-sdk-1.1.0.zip" target="_blank">v1.0.0</a></p> </section> <section class="section" id="C_SDK___section_lvd_t5m_qlb"><h2 class="doc-tairway">3. 结构体定义</h2> <p class="p">SDK中使用到的结构体,均是S3标准结构体,并未对其进行重新定义。</p> <ul class="ul" id="C_SDK___ul_zlt_zs4_qlb"> <li class="li"><strong class="ph b">S3PutProperties</strong><p class="p">S3PutProperties是在上传对象时使用到的结构体,该结构体由用户按需自行设置。结构体中的每一项都是可选的。</p><table class="table" id="C_SDK___table_amt_zs4_qlb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_amt_zs4_qlb__entry__1">项目名</th> <th class="entry" id="C_SDK___table_amt_zs4_qlb__entry__2">描述</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 "> <p class="p">const char *</p> <p class="p">contentType;</p> </td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">该项若填写,则该项需和对象类型一致。若不填写,则使用S3默认的"binary/octet-stream"类型</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 ">const char *md5;</td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">若填写,则上传时使用该MD5对内容进行校验。平安云强烈建议填写该项,但该项并非必须填写项。该项的格式是由base64编码的MD5值。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 "> <p class="p">const char *</p> <p class="p">cacheControl;</p> </td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">若填写,HTTP客户端下载时可以使用缓存到服务器的上传项。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 "> <p class="p">const char *</p> <p class="p">contentDispositionFilename;</p> </td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">若填写,通过web浏览器下载对象时,则提供下载文件保存的文件名。该项仅在打算分享给其他通过web浏览器下载而非查看的用户时使用。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 "> <p class="p">const char *</p> <p class="p">contentEncoding;</p> </td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">若填写,则该项是编码后的对象内容。该项只适用于编码后(通常情况下,也会压缩)的内容,同时,只适用于通过浏览器下载的对象。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 ">int64_t expires;</td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">若该项大于等于0,则该项描述了内容的到期日期,此信息通常只提供给通过 web 浏览器下载内容的用户。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 ">S3CannedAcl cannedAcl;</td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">这标识了应用于此对象的"可使用 ACL "。默认值(0)只提供对象所有者对它的访问。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 ">int metaDataCount;</td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">元数据域的总数量</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 ">S3NameValue *metaData;</td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">这些是要传递给 S3 的元数据,在每种情况下, 名称-值对的名称部分不应包括任何特殊的 S3 HTTP 标头前缀 (即, 应该是写"foo", 而不是 "x-amz-meta-foo")。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__1 ">int responseCode;</td> <td class="entry" headers="C_SDK___table_amt_zs4_qlb__entry__2 ">操作返回值</td> </tr> </tbody></table></li> <li class="li"><strong class="ph b">S3ResponseProperties</strong><p class="p">S3ResponseProperties是接收到完整的响应属性时,传递给回调函数设置响应的属性。此结构体的某些字段是可选的, 并且在响应中可能不提供, 有些将始终在响应中提供。</p><table class="table" id="C_SDK___table_cmt_zs4_qlb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_cmt_zs4_qlb__entry__1">项目名</th> <th class="entry" id="C_SDK___table_cmt_zs4_qlb__entry__2">描述</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">char *requestId;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">该字段是可选字段,定义了请求ID,在出现问题,向平安云报告问题时,可能会用到。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">char *requestId2;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">该字段是可选字段,定义了请求ID,在出现问题,向平安云报告问题时,可能会用到。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">char *contentType;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">该字段是可选字段,由请求定义,若有值,则该项需和对象类型一致。若没有值,则使用S3默认的"binary/octet-stream"类型。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">uint64_t contentLength;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">此可选字段是响应中返回数据的内容长度。负数表明响应未填写该值,0表明响应中没有数据内容。正数是响应中返回数据的内容比特长度。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">char *server;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">该可选字段是响应请求的服务器名称</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">char *eTag;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">此可选字段提供了一个字符串, 用于标识由请求提供的资源的唯一性, 因此, 若请求相同的资源时,得到了同样的eTag,就可以假定内容未改变。 这是一个MD5的内容总和。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">int64_t lastModified;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">此可选字段提供内容的最后修改时间(相对于UTC)。如果此值小于0, 说明响应中未提供最后修改时间. 若该值大于等于0, 则内容的最后修改日期为UTC时间以来的秒数。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">int metaDataCount;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">这是用户提供的与资源关联的元数据的数量。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">S3NameValue *metaData;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">这些是要传递给 S3 的元数据,在每种情况下, 名称-值对的名称部分不应包括任何特殊的 S3 HTTP 标头前缀 (即,“x-amz-meta-“这样的前缀不应该出现)头和尾的空格也应该被去掉。</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__1 ">int responseCode;</td> <td class="entry" headers="C_SDK___table_cmt_zs4_qlb__entry__2 ">操作返回值</td> </tr> </tbody></table></li> </ul> </section> <section class="section" id="C_SDK___section_sbl_ct4_qlb"><h2 class="doc-tairway">4. API概览</h2> <table class="table" id="C_SDK___table_qfx_2t4_qlb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_qfx_2t4_qlb__entry__1">API</th> <th class="entry" id="C_SDK___table_qfx_2t4_qlb__entry__2">描述</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">S3_init_global_info</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">配置初始化</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">S3_destroy_global_resource</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">资源注销</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">put_object</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">对象上传</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">get_object</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">对象下载</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">head_object</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">对象查询</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">del_object</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">对象删除</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">create_bucket</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">创建bucket</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__1 ">delete_bucket</td> <td class="entry" headers="C_SDK___table_qfx_2t4_qlb__entry__2 ">删除bucket</td> </tr> </tbody></table> </section> <section class="section" id="C_SDK___section_jh2_t5m_qlb"><h2 class="doc-tairway">5. Object管理接口</h2> <p class="p"><strong class="ph b">(1)S3_init_global_info</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">配置初始化</p> <p class="p"><strong class="ph b">请求参数</strong></p> <table class="table" id="C_SDK___table_rzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_rzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_rzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_rzs_gt4_qlb__entry__3">是否必须</th> <th class="entry" id="C_SDK___table_rzs_gt4_qlb__entry__4">参数描述</th> <th class="entry" id="C_SDK___table_rzs_gt4_qlb__entry__5">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_rzs_gt4_qlb__entry__1 "><em class="ph i">pathConfig</em></td> <td class="entry" headers="C_SDK___table_rzs_gt4_qlb__entry__2 "><em class="ph i">char</em></td> <td class="entry" headers="C_SDK___table_rzs_gt4_qlb__entry__3 "><em class="ph i">true</em></td> <td class="entry" headers="C_SDK___table_rzs_gt4_qlb__entry__4 "><em class="ph i">配置文件的路径</em></td> <td class="entry" headers="C_SDK___table_rzs_gt4_qlb__entry__5 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_szs_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_szs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_szs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_szs_gt4_qlb__entry__3">参数描述</th> <th class="entry" id="C_SDK___table_szs_gt4_qlb__entry__4">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_szs_gt4_qlb__entry__1 ">无</td> <td class="entry" headers="C_SDK___table_szs_gt4_qlb__entry__2 "></td> <td class="entry" headers="C_SDK___table_szs_gt4_qlb__entry__3 "></td> <td class="entry" headers="C_SDK___table_szs_gt4_qlb__entry__4 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">(2)S3_destroy_global_resource</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">资源注销,在结束使用SDK时需要调用该函数进行相关资源的注销。</p> <p class="p">请求参数</p> <table class="table" id="C_SDK___table_tzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_tzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_tzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_tzs_gt4_qlb__entry__3">是否必须</th> <th class="entry" id="C_SDK___table_tzs_gt4_qlb__entry__4">参数描述</th> <th class="entry" id="C_SDK___table_tzs_gt4_qlb__entry__5">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_tzs_gt4_qlb__entry__1 ">无</td> <td class="entry" headers="C_SDK___table_tzs_gt4_qlb__entry__2 "></td> <td class="entry" headers="C_SDK___table_tzs_gt4_qlb__entry__3 "></td> <td class="entry" headers="C_SDK___table_tzs_gt4_qlb__entry__4 "></td> <td class="entry" headers="C_SDK___table_tzs_gt4_qlb__entry__5 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_uzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_uzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_uzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_uzs_gt4_qlb__entry__3">参数描述</th> <th class="entry" id="C_SDK___table_uzs_gt4_qlb__entry__4">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_uzs_gt4_qlb__entry__1 ">无</td> <td class="entry" headers="C_SDK___table_uzs_gt4_qlb__entry__2 "></td> <td class="entry" headers="C_SDK___table_uzs_gt4_qlb__entry__3 "></td> <td class="entry" headers="C_SDK___table_uzs_gt4_qlb__entry__4 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">(3) put_object</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">对象上传</p> <p class="p"><em class="ph i">注:若使用到的参数申请了堆空间,请自行释放</em></p> <p class="p"><strong class="ph b">请求参数</strong></p> <table class="table" id="C_SDK___table_vzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_vzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_vzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_vzs_gt4_qlb__entry__3">是否必须</th> <th class="entry" id="C_SDK___table_vzs_gt4_qlb__entry__4">参数描述</th> <th class="entry" id="C_SDK___table_vzs_gt4_qlb__entry__5">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__1 ">pBucket</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__4 ">桶名</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__1 ">pKey</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__4 ">使用到的key名</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__1 ">pFilePath</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__4 ">源对象地址</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__1 ">pBucketProperties</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__2 ">S3PutProperties</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__4 ">上传所需结构体,详见结构体定义</td> <td class="entry" headers="C_SDK___table_vzs_gt4_qlb__entry__5 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_wzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_wzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_wzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_wzs_gt4_qlb__entry__3">参数描述</th> <th class="entry" id="C_SDK___table_wzs_gt4_qlb__entry__4">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_wzs_gt4_qlb__entry__1 ">responseCode</td> <td class="entry" headers="C_SDK___table_wzs_gt4_qlb__entry__2 ">int</td> <td class="entry" headers="C_SDK___table_wzs_gt4_qlb__entry__3 ">函数调用返回值</td> <td class="entry" headers="C_SDK___table_wzs_gt4_qlb__entry__4 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">(4)get_object</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">对象下载</p> <p class="p"><em class="ph i">注:若使用到的参数申请了堆空间,请自行释放</em></p> <p class="p"><strong class="ph b">请求参数</strong></p> <table class="table" id="C_SDK___table_xzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_xzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_xzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_xzs_gt4_qlb__entry__3">是否必须</th> <th class="entry" id="C_SDK___table_xzs_gt4_qlb__entry__4">参数描述</th> <th class="entry" id="C_SDK___table_xzs_gt4_qlb__entry__5">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__1 ">pBucket</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__4 ">桶名</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__1 ">pKey</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__4 ">使用到的key名</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__1 ">pFilePath</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__4 ">源对象地址</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__1 ">respProperties</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__2 ">S3ResponseProperties</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__4 ">下载所需结构体,详见结构体定义</td> <td class="entry" headers="C_SDK___table_xzs_gt4_qlb__entry__5 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_yzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_yzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_yzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_yzs_gt4_qlb__entry__3">参数描述</th> <th class="entry" id="C_SDK___table_yzs_gt4_qlb__entry__4">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_yzs_gt4_qlb__entry__1 ">responseCode</td> <td class="entry" headers="C_SDK___table_yzs_gt4_qlb__entry__2 ">int</td> <td class="entry" headers="C_SDK___table_yzs_gt4_qlb__entry__3 ">函数调用返回值</td> <td class="entry" headers="C_SDK___table_yzs_gt4_qlb__entry__4 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">(5)head_object</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">对象查询</p> <p class="p"><em class="ph i">注:若使用到的参数申请了堆空间,请自行释放</em></p> <p class="p"><strong class="ph b">请求参数</strong></p> <table class="table" id="C_SDK___table_zzs_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_zzs_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_zzs_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_zzs_gt4_qlb__entry__3">是否必须</th> <th class="entry" id="C_SDK___table_zzs_gt4_qlb__entry__4">参数描述</th> <th class="entry" id="C_SDK___table_zzs_gt4_qlb__entry__5">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__1 ">pBucket</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__4 ">桶名</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__1 ">pKey</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__4 ">使用到的key名</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__1 ">respProperties</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__2 ">S3ResponseProperties</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__4 ">查询所需结构体,详见结构体定义</td> <td class="entry" headers="C_SDK___table_zzs_gt4_qlb__entry__5 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_a1t_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_a1t_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_a1t_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_a1t_gt4_qlb__entry__3">参数描述</th> <th class="entry" id="C_SDK___table_a1t_gt4_qlb__entry__4">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_a1t_gt4_qlb__entry__1 ">responseCode</td> <td class="entry" headers="C_SDK___table_a1t_gt4_qlb__entry__2 ">int</td> <td class="entry" headers="C_SDK___table_a1t_gt4_qlb__entry__3 ">函数调用返回值</td> <td class="entry" headers="C_SDK___table_a1t_gt4_qlb__entry__4 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">(6)del_object</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">对象删除</p> <p class="p"><em class="ph i">注:若使用到的参数申请了堆空间,请自行释放</em></p> <p class="p"><strong class="ph b">请求参数</strong></p> <table class="table" id="C_SDK___table_b1t_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_b1t_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_b1t_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_b1t_gt4_qlb__entry__3">是否必须</th> <th class="entry" id="C_SDK___table_b1t_gt4_qlb__entry__4">参数描述</th> <th class="entry" id="C_SDK___table_b1t_gt4_qlb__entry__5">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__1 ">pBucket</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__4 ">桶名</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__1 ">pKey</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__4 ">使用到的key名</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__5 "></td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__1 ">pBucketProperties</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__2 ">S3PutProperties</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__4 ">删除所需结构体,详见结构体定义</td> <td class="entry" headers="C_SDK___table_b1t_gt4_qlb__entry__5 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_c1t_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_c1t_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_c1t_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_c1t_gt4_qlb__entry__3">参数描述</th> <th class="entry" id="C_SDK___table_c1t_gt4_qlb__entry__4">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_c1t_gt4_qlb__entry__1 ">responseCode</td> <td class="entry" headers="C_SDK___table_c1t_gt4_qlb__entry__2 ">int</td> <td class="entry" headers="C_SDK___table_c1t_gt4_qlb__entry__3 ">函数调用返回值</td> <td class="entry" headers="C_SDK___table_c1t_gt4_qlb__entry__4 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">6. HTTP状态码</strong></p> <table class="table" id="C_SDK___table_d1t_gt4_qlb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_d1t_gt4_qlb__entry__1">状态码</th> <th class="entry" id="C_SDK___table_d1t_gt4_qlb__entry__2">说明</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__1 ">200</td> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__2 ">成功</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__1 ">204</td> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__2 ">删除资源成功</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__1 ">404</td> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__2 ">资源不存在(对象不存在、bucket不存在等)</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__1 ">403</td> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__2 ">权限不正确</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__1 ">500</td> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__2 ">服务器错误</td> </tr> <tr class="row"> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__1 ">0</td> <td class="entry" headers="C_SDK___table_d1t_gt4_qlb__entry__2 ">未实际执行操作</td> </tr> </tbody></table> <p class="p"><em class="ph i">注:其他状态码请参照libs3.h中的</em><em class="ph i">S3Status</em></p> <p class="p"><strong class="ph b">7. 代码示例</strong></p> <table class="table" id="C_SDK___table_e1t_gt4_qlb"><caption></caption><colgroup><col></colgroup><tbody class="tbody"> <tr class="row"> <td class="entry"> <p class="p">#include <stdio.h></p> <p class="p">#include <stdlib.h></p> <p class="p">#include <string.h></p> <p class="p">#include <time.h></p> <p class="p">#include<pthread.h></p> <p class="p">#include <unistd.h></p> <p class="p">#include <sys/types.h></p> <p class="p">#include <sys/syscall.h></p> <p class="p">#include "libs3.h"</p> <p class="p">void initResponseProperties(S3ResponseProperties *responseProperties)</p> <p class="p">{</p> <p class="p"> <strong class="ph b">//</strong><strong class="ph b">初始化资源</strong></p> <p class="p"> memset(responseProperties, 0, sizeof(S3ResponseProperties));</p> <p class="p"> responseProperties->requestId = (char *)malloc(1024 * sizeof(char));</p> <p class="p"> memset(responseProperties->requestId, 0, 1024 * sizeof(char));</p> <p class="p"> responseProperties->requestId2 = (char *)malloc(1024 * sizeof(char));</p> <p class="p"> memset(responseProperties->requestId2, 0, 1024 * sizeof(char));</p> <p class="p"> responseProperties->contentType = (char *)malloc(1024 * sizeof(char));</p> <p class="p"> memset(responseProperties->contentType, 0, 1024 * sizeof(char));</p> <p class="p"> responseProperties->server= (char *)malloc(1024 * sizeof(char));</p> <p class="p"> memset(responseProperties->server, 0, 1024 * sizeof(char));</p> <p class="p"> responseProperties->eTag= (char *)malloc(1024 * sizeof(char));</p> <p class="p"> memset(responseProperties->eTag, 0, 1024 * sizeof(char));</p> <p class="p"> responseProperties->metaData = (S3NameValue *)malloc(sizeof(struct S3NameValue) * 100);</p> <p class="p"> memset(responseProperties->metaData, 0, sizeof(struct S3NameValue) * 100);</p> <p class="p"> int i = 0; for (i = 0; i < 100; ++i)</p> <p class="p"> {</p> <p class="p"> responseProperties->metaData[i].name = (char *)malloc(1024 * sizeof(char));</p> <p class="p"> memset(responseProperties->metaData[i].name, 0, 1024 * sizeof(char));</p> <p class="p"> responseProperties->metaData[i].value = (char *)malloc(1024 * sizeof(char));</p> <p class="p"> memset(responseProperties->metaData[i].value, 0, 1024 * sizeof(char));</p> <p class="p"> }</p> <p class="p">}</p> <p class="p">void destroyResponseProperties(S3ResponseProperties *responseProperties)</p> <p class="p">{</p> <p class="p"> <strong class="ph b">//</strong><strong class="ph b">销毁资源</strong></p> <p class="p"> free(responseProperties->requestId);</p> <p class="p"> responseProperties->requestId=NULL;</p> <p class="p"> free(responseProperties->requestId2);</p> <p class="p"> responseProperties->requestId2 = NULL;</p> <p class="p"> </p> <p class="p"> free(responseProperties->contentType);</p> <p class="p"> responseProperties->contentType=NULL;</p> <p class="p"> </p> <p class="p"> free(responseProperties->server);</p> <p class="p"> responseProperties->server=NULL;</p> <p class="p"> </p> <p class="p"> free(responseProperties->eTag);</p> <p class="p"> responseProperties->eTag=NULL;</p> <p class="p"> </p> <p class="p"> free(responseProperties->metaData);</p> <p class="p"> responseProperties->metaData=NULL;</p> <p class="p"> </p> <p class="p"> </p> <p class="p">}</p> <p class="p">void demo_put(char *bucket, char *object, char *filename)</p> <p class="p">{</p> <p class="p"> <strong class="ph b">//</strong><strong class="ph b">上传对象</strong></p> <p class="p"> S3PutProperties test;</p> <p class="p"> memset(&test, 0, sizeof(S3PutProperties));</p> <p class="p"> int iret = put_object(bucket, object, filename, &test);</p> <p class="p"> printf("put:%s:%d:%d\n", object, iret, test.responseCode);</p> <p class="p">}</p> <p class="p">void demo_get(char *bucket, char *object, char *filename)</p> <p class="p">{</p> <p class="p"> <strong class="ph b"> //</strong><strong class="ph b">下载对象</strong></p> <p class="p"> S3ResponseProperties respProperties;</p> <p class="p"> initResponseProperties(&respProperties);</p> <p class="p"> int iret = get_object(bucket, object, filename, &respProperties);</p> <p class="p"> printf("get:%s:%d:%d:%s\n", object, iret, respProperties.responseCode, respProperties.eTag);</p> <p class="p"> destroyResponseProperties(&respProperties);</p> <p class="p">}</p> <p class="p">void demo_head(char *bucket, char *object)</p> <p class="p">{</p> <p class="p"> <strong class="ph b">//</strong><strong class="ph b">查询对象</strong></p> <p class="p"> S3ResponseProperties headProperties;</p> <p class="p"> initResponseProperties(&headProperties);</p> <p class="p"> int iret = head_object(bucket, object, &headProperties);</p> <p class="p"> printf("head:%s:%d:%d:%s\n", object, iret, headProperties.responseCode, headProperties.eTag);</p> <p class="p"> destroyResponseProperties(&headProperties);</p> <p class="p">}</p> <p class="p">void demo_del(char *bucket, char *object)</p> <p class="p">{</p> <p class="p"> <strong class="ph b">//</strong><strong class="ph b">删除对象</strong></p> <p class="p"> S3PutProperties test;</p> <p class="p"> int iret = del_object(bucket, object, &test);</p> <p class="p"> printf("del:%s:%d:%d\n", object, iret, test.responseCode);</p> <p class="p">}</p> <p class="p">int main()</p> <p class="p">{</p> <p class="p">char config_path[256] = "server.conf";</p> <p class="p">char bucket[10] = "csdk1";</p> <p class="p">char object[50] = "big.qq";</p> <p class="p">char filename[100] = "./put/big.qq";</p> <p class="p">char getfilename[100] = "./get/big.qq";</p> <p class="p"><strong class="ph b">//初始化配置</strong></p> <p class="p">S3_init_global_info(config_path);</p> <p class="p">demo_put(bucket, object, filename);</p> <p class="p">demo_get(bucket, object, getfilename);</p> <p class="p">demo_head(bucket, object);</p> <p class="p">demo_del(bucket, object);</p> <p class="p">S3_destroy_global_resource();</p> <p class="p">return 0;</p> <p class="p">}</p> </td> </tr> </tbody></table> <p class="p"><strong class="ph b">8. Bucket管理接口</strong></p> <p class="p"><strong class="ph b">(1) create_bucket</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">创建bucket</p> <p class="p"><em class="ph i">注:若使用到的参数申请了堆空间,请自行释放</em></p> <p class="p"><strong class="ph b">请求参数</strong></p> <table class="table" id="C_SDK___table_f1t_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="C_SDK___table_f1t_gt4_qlb__entry__1">参数名称</th> <th class="entry" id="C_SDK___table_f1t_gt4_qlb__entry__2">参数类型</th> <th class="entry" id="C_SDK___table_f1t_gt4_qlb__entry__3">是否必须</th> <th class="entry" id="C_SDK___table_f1t_gt4_qlb__entry__4">参数描述</th> <th class="entry" id="C_SDK___table_f1t_gt4_qlb__entry__5">备注</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="C_SDK___table_f1t_gt4_qlb__entry__1 ">pBucket</td> <td class="entry" headers="C_SDK___table_f1t_gt4_qlb__entry__2 ">char</td> <td class="entry" headers="C_SDK___table_f1t_gt4_qlb__entry__3 ">true</td> <td class="entry" headers="C_SDK___table_f1t_gt4_qlb__entry__4 ">桶名</td> <td class="entry" headers="C_SDK___table_f1t_gt4_qlb__entry__5 "></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_g1t_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><tbody class="tbody"> <tr class="row"> <td class="entry"><strong class="ph b">参数名称</strong></td> <td class="entry"><strong class="ph b">参数类型</strong></td> <td class="entry"><strong class="ph b">参数描述</strong></td> <td class="entry"><strong class="ph b">备注</strong></td> </tr> <tr class="row"> <td class="entry">responseCode</td> <td class="entry">int</td> <td class="entry">函数调用返回值</td> <td class="entry"></td> </tr> </tbody></table> <p class="p"><strong class="ph b">(2) delete_bucket</strong></p> <p class="p"><strong class="ph b">接口描述</strong></p> <p class="p">删除bucket</p> <p class="p"><em class="ph i">注:若使用到的参数申请了堆空间,请自行释放</em></p> <p class="p"><strong class="ph b">请求参数</strong></p> <table class="table" id="C_SDK___table_h1t_gt4_qlb"><caption></caption><colgroup><col><col><col><col><col></colgroup><tbody class="tbody"> <tr class="row"> <td class="entry"><strong class="ph b">参数名称</strong></td> <td class="entry"><strong class="ph b">参数类型</strong></td> <td class="entry"><strong class="ph b">是否必须</strong></td> <td class="entry"><strong class="ph b">参数描述</strong></td> <td class="entry"><strong class="ph b">备注</strong></td> </tr> <tr class="row"> <td class="entry">pBucket</td> <td class="entry">char</td> <td class="entry">true</td> <td class="entry">桶名</td> <td class="entry"></td> </tr> </tbody></table> <p class="p"><strong class="ph b">响应参数</strong></p> <table class="table" id="C_SDK___table_i1t_gt4_qlb"><caption></caption><colgroup><col><col><col><col></colgroup><tbody class="tbody"> <tr class="row"> <td class="entry"><strong class="ph b">参数名称</strong></td> <td class="entry"><strong class="ph b">参数类型</strong></td> <td class="entry"><strong class="ph b">参数描述</strong></td> <td class="entry"><strong class="ph b">备注</strong></td> </tr> <tr class="row"> <td class="entry">responseCode</td> <td class="entry">int</td> <td class="entry">函数调用返回值</td> <td class="entry"></td> </tr> </tbody></table> <p class="p"><strong class="ph b">(3) 接口返回值</strong></p> <table class="table" id="C_SDK___table_j1t_gt4_qlb"><caption></caption><colgroup><col><col></colgroup><tbody class="tbody"> <tr class="row"> <td class="entry"><strong class="ph b">状态码</strong></td> <td class="entry"><strong class="ph b">说明</strong></td> </tr> <tr class="row"> <td class="entry">0</td> <td class="entry">成功</td> </tr> <tr class="row"> <td class="entry">1</td> <td class="entry">未输入参数</td> </tr> <tr class="row"> <td class="entry">4~9</td> <td class="entry">非法的bucket名</td> </tr> <tr class="row"> <td class="entry">103</td> <td class="entry">权限错误</td> </tr> </tbody></table> <p class="p"><em class="ph i">注:其他状态码请参照libs3.h中的</em><em class="ph i">S3Status</em></p> <p class="p"><strong class="ph b">(4) 代码示例</strong></p> <table class="table" id="C_SDK___table_k1t_gt4_qlb"><caption></caption><colgroup><col></colgroup><tbody class="tbody"> <tr class="row"> <td class="entry"> <p class="p">#include <stdio.h></p> <p class="p">#include <stdlib.h></p> <p class="p">#include <string.h></p> <p class="p">#include <unistd.h></p> <p class="p">#include <sys/types.h></p> <p class="p">#include <sys/syscall.h></p> <p class="p">#include "libs3.h"</p> <p class="p">int main()</p> <p class="p">{</p> <p class="p">char config_path[256] = "server.conf";</p> <p class="p">char bucket[10] = "csdk2";</p> <p class="p">int ret=-100;</p> <p class="p">//初始化配置</p> <p class="p">S3_init_global_info(config_path);</p> <p class="p">ret = create_bucket(bucket);</p> <p class="p">printf("%d\n", ret);</p> <p class="p">ret = delete_bucket(bucket);</p> <p class="p">printf("%d\n", ret);</p> <p class="p">S3_destroy_global_resource();</p> <p class="p">return 0;</p> <p class="p">}</p> </td> </tr> </tbody></table> </section>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

工单支持

解决云产品相关技术问题