C SDK

<p><strong>1.&nbsp;简介</strong></p> <ul> <li>本文档主要介绍 OBS C SDK 的接口使用及注意事项;</li> <li>并且假设您已经开通了 OBS 服务,并已是平安公有云用户;</li> <li>如果您还没有开通或者还不了解平安公有云OBS服务,请登录平安公有云主页进行了解。</li> <li>OBS-C-SDK 是由平安云团队开发的工具包。便于开发者在 C语言环境下方便使用平安云当中的 OBS 服务。</li> <li>文档主要罗列了OBS-C-SDK中,上传、下载以及删除的一些基本方法,并对方法参数进行简要解释,且对响应方法有一个详细的说明。</li> </ul> <p>&nbsp;</p> <p><strong>2. SDK下载</strong></p> <p>C SDK 开发包最新版本&nbsp;<a href="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/sdk%2Fobs-c-sdk-1.0.0.zip?response-content-disposition=attachment%3Bfilename%3Dobs-c-sdk-1.0.0.zip">v1.0.0</a></p> <p>&nbsp;</p> <p><strong>3.&nbsp;结构体定义</strong></p> <p>SDK中使用到的结构体,均是S3标准结构体,并未对其进行重新定义。</p> <ul> <li><strong>S3PutProperties</strong></li> </ul> <p>S3PutProperties是在上传对象时使用到的结构体,该结构体由用户按需自行设置。结构体中的每一项都是可选的。</p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p>项目名</p> </td> <td> <p><strong>描述</strong></p> </td> </tr> <tr> <td> <p><em>const char *</em></p> <p><em>contentType;</em></p> </td> <td> <p><em>该项若填写,则该项需和对象类型一致。若不填写,则使用S3默认的&quot;binary/octet-stream&quot;类型</em></p> </td> </tr> <tr> <td> <p><em>const char *md5;</em></p> </td> <td> <p><em>若填写,则上传时使用该MD5对内容进行校验。平安云强烈建议填写该项,但该项并非必须填写项。该项的格式是由base64编码的MD5值。</em></p> </td> </tr> <tr> <td> <p><em>const char *</em></p> <p><em>cacheControl;</em></p> </td> <td> <p><em>若填写,HTTP客户端下载时可以使用缓存到服务器的上传项。</em></p> </td> </tr> <tr> <td> <p><em>const char *</em></p> <p><em>contentDispositionFilename;</em></p> </td> <td> <p><em>若填写,通过web浏览器下载对象时,则提供下载文件保存的文件名。该项仅在打算分享给其他通过web浏览器下载而非查看的用户时使用。</em></p> </td> </tr> <tr> <td> <p><em>const char *</em></p> <p><em>contentEncoding;</em></p> </td> <td> <p><em>若填写,则该项是编码后的对象内容。该项只适用于编码后(通常情况下,也会压缩)的内容,同时,只适用于通过浏览器下载的对象。</em></p> </td> </tr> <tr> <td> <p><em>int64_t expires;</em></p> </td> <td> <p><em>若该项大于等于0,则该项描述了内容的到期日期,此信息通常只提供给通过 web 浏览器下载内容的用户。</em></p> </td> </tr> <tr> <td> <p><em>S3CannedAcl cannedAcl;</em></p> </td> <td> <p><em>这标识了应用于此对象的&quot;可使用 ACL &quot;。默认值(0)只提供对象所有者对它的访问。</em></p> </td> </tr> <tr> <td> <p><em>int metaDataCount;</em></p> </td> <td> <p><em>元数据域的总数量</em></p> </td> </tr> <tr> <td> <p><em>S3NameValue *metaData;</em></p> </td> <td> <p><em>这些是要传递给 S3 的元数据,在每种情况下, 名称-值对的名称部分不应包括任何特殊的 S3 HTTP 标头前缀 (即, 应该是写&quot;foo&quot;, 而不是 &quot;x-amz-meta-foo&quot;)。</em></p> </td> </tr> <tr> <td> <p><em>int responseCode;</em></p> </td> <td> <p><em>操作返回值</em></p> </td> </tr> </tbody> </table> <ul> <li><strong>S3ResponseProperties</strong></li> </ul> <p>S3ResponseProperties是接收到完整的响应属性时,传递给回调函数设置响应的属性。此结构体的某些字段是可选的, 并且在响应中可能不提供, 有些将始终在响应中提供。</p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p>项目名</p> </td> <td> <p><strong>描述</strong></p> </td> </tr> <tr> <td> <p><em>char *requestId;</em></p> </td> <td> <p><em>该字段是可选字段,定义了请求ID,在出现问题,向平安云报告问题时,可能会用到。</em></p> </td> </tr> <tr> <td> <p><em>char *requestId2;</em></p> </td> <td> <p><em>该字段是可选字段,定义了请求ID,在出现问题,向平安云报告问题时,可能会用到。</em></p> </td> </tr> <tr> <td> <p><em>char *contentType;</em></p> </td> <td> <p><em>该字段是可选字段,由请求定义,若有值,则该项需和对象类型一致。若没有值,则使用S3默认的&quot;binary/octet-stream&quot;类型。</em></p> </td> </tr> <tr> <td> <p><em>uint64_t contentLength;</em></p> </td> <td> <p><em>此可选字段是响应中返回数据的内容长度。负数表明响应未填写该值,0表明响应中没有数据内容。正数是响应中返回数据的内容比特长度。</em></p> </td> </tr> <tr> <td> <p><em>char *server;</em></p> </td> <td> <p><em>该可选字段是响应请求的服务器名称</em></p> </td> </tr> <tr> <td> <p><em>char *eTag;</em></p> </td> <td> <p><em>此可选字段提供了一个字符串, 用于标识由请求提供的资源的唯一性, 因此, 若请求相同的资源时,得到了同样的eTag,就可以假定内容未改变。 这是一个MD5的内容总和。</em></p> </td> </tr> <tr> <td> <p><em>int64_t lastModified;</em></p> </td> <td> <p><em>此可选字段提供内容的最后修改时间(相对于UTC)。如果此值小于0, 说明响应中未提供最后修改时间. 若该值大于等于0, 则内容的最后修改日期为UTC时间以来的秒数。</em></p> </td> </tr> <tr> <td> <p><em>int metaDataCount;</em></p> </td> <td> <p><em>这是用户提供的与资源关联的元数据的数量。</em></p> </td> </tr> <tr> <td> <p><em>S3NameValue *metaData;</em></p> </td> <td> <p><em>这些是要传递给 S3 的元数据,在每种情况下, 名称-值对的名称部分不应包括任何特殊的 S3 HTTP 标头前缀 (即,&ldquo;x-amz-meta-&ldquo;这样的前缀不应该出现)头和尾的空格也应该被去掉。</em></p> </td> </tr> <tr> <td> <p><em>int responseCode;</em></p> </td> <td> <p><em>操作返回值</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>4.&nbsp;API概览</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>API</strong></p> </td> <td> <p><strong>描述</strong></p> </td> </tr> <tr> <td> <p><em>S3_init_global_info</em></p> </td> <td> <p><em>配置初始化</em></p> </td> </tr> <tr> <td> <p><em>S3_destroy_global_resource</em></p> </td> <td> <p><em>资源注销</em></p> </td> </tr> <tr> <td> <p><em>put_object</em></p> </td> <td> <p><em>对象上传</em></p> </td> </tr> <tr> <td> <p><em>get_object</em></p> </td> <td> <p><em>对象下载</em></p> </td> </tr> <tr> <td> <p><em>head_object</em></p> </td> <td> <p><em>对象查询</em></p> </td> </tr> <tr> <td> <p><em>del_object</em></p> </td> <td> <p><em>对象删除</em></p> </td> </tr> <tr> <td> <p><em>create_bucket</em></p> </td> <td> <p><em>创建bucket</em></p> </td> </tr> <tr> <td> <p><em>delete_bucket</em></p> </td> <td> <p><em>删除bucket</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>5.&nbsp;API描述</strong></p> <p><strong>(1)S3_init_global_info</strong></p> <p><strong>接口描述</strong></p> <p>配置初始化</p> <p><strong>请求参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>pathConfig</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>配置文件的路径</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>(2)S3_destroy_global_resource</strong></p> <p><strong>接口描述</strong></p> <p>资源注销,在结束使用SDK时需要调用该函数进行相关资源的注销。</p> <p>请求参数</p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>(3) put_object</strong></p> <p><strong>接口描述</strong></p> <p>对象上传</p> <p><em>注:若使用到的参数申请了堆空间,请自行释放</em></p> <p><strong>请求参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>pBucket</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>桶名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pKey</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>使用到的key名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pFilePath</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>源对象地址</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pBucketProperties</em></p> </td> <td> <p><em>S3PutProperties</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>上传所需结构体,详见</em><em>结构体定义</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>responseCode</em></p> </td> <td> <p><em>int</em></p> </td> <td> <p><em>函数调用返回值</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>(4)get_object</strong></p> <p><strong>接口描述</strong></p> <p>对象下载</p> <p><em>注:若使用到的参数申请了堆空间,请自行释放</em></p> <p><strong>请求参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>pBucket</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>桶名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pKey</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>使用到的key名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pFilePath</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>源对象地址</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>respProperties</em></p> </td> <td> <p><em>S3ResponseProperties</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>下载所需结构体,详见</em><em>结构体定义</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>responseCode</em></p> </td> <td> <p><em>int</em></p> </td> <td> <p><em>函数调用返回值</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>(5)head_object</strong></p> <p><strong>接口描述</strong></p> <p>对象查询</p> <p><em>注:若使用到的参数申请了堆空间,请自行释放</em></p> <p><strong>请求参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>pBucket</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>桶名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pKey</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>使用到的key名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>respProperties</em></p> </td> <td> <p><em>S3ResponseProperties</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>查询所需结构体,详见</em><em>结构体定义</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>responseCode</em></p> </td> <td> <p><em>int</em></p> </td> <td> <p><em>函数调用返回值</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>(6)del_object</strong></p> <p><strong>接口描述</strong></p> <p>对象删除</p> <p><em>注:若使用到的参数申请了堆空间,请自行释放</em></p> <p><strong>请求参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>pBucket</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>桶名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pKey</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>使用到的key名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> <tr> <td> <p><em>pBucketProperties</em></p> </td> <td> <p><em>S3PutProperties</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>删除所需结构体,详见</em><em>结构体定义</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>responseCode</em></p> </td> <td> <p><em>int</em></p> </td> <td> <p><em>函数调用返回值</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>6.&nbsp;HTTP状态码</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>状态码</strong></p> </td> <td> <p><strong>说明</strong></p> </td> </tr> <tr> <td> <p><em>200</em></p> </td> <td> <p><em>成功</em></p> </td> </tr> <tr> <td> <p><em>204</em></p> </td> <td> <p><em>删除资源成功</em></p> </td> </tr> <tr> <td> <p><em>404</em></p> </td> <td> <p><em>资源不存在(对象不存在、bucket不存在等)</em></p> </td> </tr> <tr> <td> <p><em>403</em></p> </td> <td> <p><em>权限不正确</em></p> </td> </tr> <tr> <td> <p><em>500</em></p> </td> <td> <p><em>服务器错误</em></p> </td> </tr> <tr> <td> <p><em>0</em></p> </td> <td> <p><em>未实际执行操作</em></p> </td> </tr> </tbody> </table> <p><em>注:其他状态码请参照libs3.h中的</em><em>S3Status</em></p> <p>&nbsp;</p> <p><strong>6.&nbsp;代码示例</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="vertical-align:top"> <p>#include &lt;stdio.h&gt;</p> <p>#include &lt;stdlib.h&gt;</p> <p>#include &lt;string.h&gt;</p> <p>#include &lt;time.h&gt;</p> <p>#include&lt;pthread.h&gt;</p> <p>#include &lt;unistd.h&gt;</p> <p>#include &lt;sys/types.h&gt;</p> <p>#include &lt;sys/syscall.h&gt;</p> <p>&nbsp;</p> <p>#include &quot;libs3.h&quot;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>void initResponseProperties(S3ResponseProperties *responseProperties)</p> <p>{</p> <p>&nbsp;&nbsp; &nbsp;<strong>//</strong><strong>初始化资源</strong></p> <p>&nbsp;&nbsp;&nbsp; memset(responseProperties, 0, sizeof(S3ResponseProperties));</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;requestId = (char *)malloc(1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;requestId, 0, 1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;requestId2 = (char *)malloc(1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;requestId2, 0, 1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;contentType = (char *)malloc(1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;contentType, 0, 1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;server= (char *)malloc(1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;server, 0, 1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;eTag= (char *)malloc(1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;eTag, 0, 1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;metaData = (S3NameValue *)malloc(sizeof(struct S3NameValue) * 100);</p> <p>&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;metaData, 0, sizeof(struct S3NameValue) * 100);</p> <p>&nbsp;&nbsp;&nbsp; int i = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; 100; ++i)</p> <p>&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; responseProperties-&gt;metaData[i].name = (char *)malloc(1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;metaData[i].name, 0, 1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; responseProperties-&gt;metaData[i].value = (char *)malloc(1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memset(responseProperties-&gt;metaData[i].value, 0, 1024 * sizeof(char));</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>}</p> <p>&nbsp;</p> <p>void destroyResponseProperties(S3ResponseProperties *responseProperties)</p> <p>{</p> <p>&nbsp;&nbsp;&nbsp; <strong>//</strong><strong>销毁资源</strong></p> <p>&nbsp;&nbsp;&nbsp; free(responseProperties-&gt;requestId);</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;requestId=NULL;</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; free(responseProperties-&gt;requestId2);</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;requestId2 = NULL;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; free(responseProperties-&gt;contentType);</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;contentType=NULL;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; free(responseProperties-&gt;server);</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;server=NULL;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; free(responseProperties-&gt;eTag);</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;eTag=NULL;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; free(responseProperties-&gt;metaData);</p> <p>&nbsp;&nbsp;&nbsp; responseProperties-&gt;metaData=NULL;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>}</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>void demo_put(char *bucket, char *object, char *filename)</p> <p>{</p> <p>&nbsp;&nbsp;&nbsp; <strong>//</strong><strong>上传对象</strong></p> <p>&nbsp;&nbsp;&nbsp; S3PutProperties test;</p> <p>&nbsp;&nbsp;&nbsp; memset(&amp;test, 0, sizeof(S3PutProperties));</p> <p>&nbsp;&nbsp;&nbsp; int iret = put_object(bucket, object, filename, &amp;test);</p> <p>&nbsp;&nbsp;&nbsp; printf(&quot;put:%s:%d:%d\n&quot;, object, iret, test.responseCode);</p> <p>}</p> <p>&nbsp;</p> <p>void demo_get(char *bucket, char *object, char *filename)</p> <p>{</p> <p>&nbsp;&nbsp; <strong>&nbsp;//</strong><strong>下载对象</strong></p> <p>&nbsp;&nbsp;&nbsp; S3ResponseProperties respProperties;</p> <p>&nbsp;&nbsp;&nbsp; initResponseProperties(&amp;respProperties);</p> <p>&nbsp;&nbsp;&nbsp; int iret = get_object(bucket, object, filename, &amp;respProperties);</p> <p>&nbsp;&nbsp;&nbsp; printf(&quot;get:%s:%d:%d:%s\n&quot;, object, iret, respProperties.responseCode, respProperties.eTag);</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; destroyResponseProperties(&amp;respProperties);</p> <p>}</p> <p>&nbsp;</p> <p>void demo_head(char *bucket, char *object)</p> <p>{</p> <p>&nbsp;&nbsp;&nbsp; <strong>//</strong><strong>查询对象</strong></p> <p>&nbsp;&nbsp;&nbsp; S3ResponseProperties headProperties;</p> <p>&nbsp;&nbsp;&nbsp; initResponseProperties(&amp;headProperties);</p> <p>&nbsp;&nbsp;&nbsp; int iret = head_object(bucket, object, &amp;headProperties);</p> <p>&nbsp;&nbsp;&nbsp; printf(&quot;head:%s:%d:%d:%s\n&quot;, object, iret, headProperties.responseCode, headProperties.eTag);</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; destroyResponseProperties(&amp;headProperties);</p> <p>}</p> <p>&nbsp;</p> <p>void demo_del(char *bucket, char *object)</p> <p>{</p> <p>&nbsp;&nbsp;&nbsp; <strong>//</strong><strong>删除对象</strong></p> <p>&nbsp;&nbsp;&nbsp; S3PutProperties test;</p> <p>&nbsp;&nbsp;&nbsp; int iret = del_object(bucket, object, &amp;test);</p> <p>&nbsp;&nbsp;&nbsp; printf(&quot;del:%s:%d:%d\n&quot;, object, iret, test.responseCode);</p> <p>}</p> <p>&nbsp;</p> <p>int main()</p> <p>{</p> <p>char config_path[256] = &quot;server.conf&quot;;</p> <p>char bucket[10] = &quot;csdk1&quot;;</p> <p>char object[50] = &quot;big.qq&quot;;</p> <p>char filename[100] = &quot;./put/big.qq&quot;;</p> <p>char getfilename[100] = &quot;./get/big.qq&quot;;</p> <p>&nbsp;</p> <p><strong>//初始化配置</strong></p> <p>S3_init_global_info(config_path);</p> <p>&nbsp;</p> <p>demo_put(bucket, object, filename);</p> <p>demo_get(bucket, object, getfilename);</p> <p>demo_head(bucket, object);</p> <p>demo_del(bucket, object);</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>S3_destroy_global_resource();</p> <p>return 0;</p> <p>}</p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>7.&nbsp;Bucket管理接口</strong></p> <p><strong>(1) create_bucket</strong></p> <p><strong>接口描述</strong></p> <p>创建bucket</p> <p><em>注:若使用到的参数申请了堆空间,请自行释放</em></p> <p><strong>请求参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>pBucket</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>桶名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>responseCode</em></p> </td> <td> <p><em>int</em></p> </td> <td> <p><em>函数调用返回值</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>(2) delete_bucket</strong></p> <p><strong>接口描述</strong></p> <p>删除bucket</p> <p><em>注:若使用到的参数申请了堆空间,请自行释放</em></p> <p><strong>请求参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>是否必须</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>pBucket</em></p> </td> <td> <p><em>char</em></p> </td> <td> <p><em>true</em></p> </td> <td> <p><em>桶名</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p><strong>响应参数</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>参数名称</strong></p> </td> <td> <p><strong>参数类型</strong></p> </td> <td> <p><strong>参数描述</strong></p> </td> <td> <p><strong>备注</strong></p> </td> </tr> <tr> <td> <p><em>responseCode</em></p> </td> <td> <p><em>int</em></p> </td> <td> <p><em>函数调用返回值</em></p> </td> <td> <p><em>&nbsp;</em></p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p><strong>(3) 接口返回值</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <p><strong>状态码</strong></p> </td> <td> <p><strong>说明</strong></p> </td> </tr> <tr> <td> <p><em>0</em></p> </td> <td> <p><em>成功</em></p> </td> </tr> <tr> <td> <p><em>1</em></p> </td> <td> <p><em>未输入参数</em></p> </td> </tr> <tr> <td> <p><em>4~9</em></p> </td> <td> <p><em>非法的bucket名</em></p> </td> </tr> <tr> <td> <p><em>103</em></p> </td> <td> <p><em>权限错误</em></p> </td> </tr> </tbody> </table> <p><em>注:其他状态码请参照libs3.h中的</em><em>S3Status</em></p> <p>&nbsp;</p> <p><strong>(4) 代码示例</strong></p> <table border="1" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="vertical-align:top"> <p>#include &lt;stdio.h&gt;</p> <p>#include &lt;stdlib.h&gt;</p> <p>#include &lt;string.h&gt;</p> <p>#include &lt;unistd.h&gt;</p> <p>#include &lt;sys/types.h&gt;</p> <p>#include &lt;sys/syscall.h&gt;</p> <p>&nbsp;</p> <p>#include &quot;libs3.h&quot;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>int main()</p> <p>{</p> <p>char config_path[256] = &quot;server.conf&quot;;</p> <p>char bucket[10] = &quot;csdk2&quot;;</p> <p>int ret=-100;</p> <p>//初始化配置</p> <p>S3_init_global_info(config_path);</p> <p>&nbsp;</p> <p>ret = create_bucket(bucket);</p> <p>printf(&quot;%d\n&quot;, ret);</p> <p>ret = delete_bucket(bucket);</p> <p>printf(&quot;%d\n&quot;, ret);</p> <p>&nbsp;</p> <p>S3_destroy_global_resource();</p> <p>return 0;</p> <p>}</p> </td> </tr> </tbody> </table> <p>&nbsp;</p>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询 - 7x24 小时

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

7x24 小时,急速解答

工单支持

解决云产品相关技术问题