• 使用curl进行s3服务操作


    最近使用curl对s3进行接口测试,本想写个总结文档,但没想到已有前辈写了,就直接搬过来做个记录吧,原文见:

    http://blog.csdn.net/ganggexiongqi/article/details/50483389

    不想使用s3cmd/s3curl等工具或者第三方库来测试RadosGW提供的s3服务。所以google了一把,已经有人做过了,详见参考链接。

    贴个shell脚本做个记录。

    1. 创建bucket

    创建名为"mygod"的bucket

    bucket="mygod"  
    dateValue=`date -R`  
    resource="/${bucket}/"  
    contentType="application/octet-stream"  
    stringToSign="PUT
    
    
    ${dateValue}
    ${resource}"  
    s3Key="6R2MJWR863EREUDD0KTZ"  
    s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    curl -v -X PUT "http://${bucket}.s3.mydomain.com"   
            -H "Host: ${bucket}.s3.mydomain.com"   
            -H "Date: ${dateValue}"  
            -H "Authorization: AWS ${s3Key}:${signature}"
    

      

    2. 上传对象到bucket

     

    下面的脚本就是将@file上传到@url指定的存储服务集群中的@bucket下,对象的名字叫@objname。

    file=./c.zip  
    objname="testfile"  
    bucket=another  
    url="s3.mydomain.com"  
    resource="/${bucket}/${objname}"  
    contentType="application/x-compressed-tar"  
    dateValue=`date -R`  
    stringToSign="PUT
    
    ${contentType}
    ${dateValue}
    ${resource}"  
    s3Key="6R2MJWR863EREUDD0KTZ"  
    s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    curl -X PUT -T "${file}"   
      -H "Host: ${bucket}.${url}"   
      -H "Date: ${dateValue}"   
      -H "Content-Type: ${contentType}"   
      -H "Authorization: AWS ${s3Key}:${signature}" "http://${bucket}.${url}/${objname}" 
    

      

    3. 获取object

    file="./myfile"  
    objname="testfile"  
    bucket=another  
    url="s3.mydomain.com"  
    resource="/${bucket}/${objname}"  
    contentType="application/x-compressed-tar"  
    dateValue=`date -R`  
    stringToSign="GET
    
    ${contentType}
    ${dateValue}
    ${resource}"  
    s3Key="6R2MJWR863EREUDD0KTZ"  
    s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    curl -o ${file} -X GET   
      -H "Host: ${bucket}.${url}"   
      -H "Date: ${dateValue}"   
      -H "Content-Type: ${contentType}"   
      -H "Authorization: AWS ${s3Key}:${signature}" "http://${bucket}.${url}/${objname}" 
    

      

    1. bucket="mygod"  
    2. dateValue=`date -R`  
    3. resource="/${bucket}/"  
    4. contentType="application/octet-stream"  
    5. stringToSign="PUT ${dateValue} ${resource}"  
    6. s3Key="6R2MJWR863EREUDD0KTZ"  
    7. s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    8. signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    9. curl -v -X PUT "http://${bucket}.s3.mydomain.com"   
    10.         -H "Host: ${bucket}.s3.mydomain.com"   
    11.         -H "Date: ${dateValue}"  
    12.         -H "Authorization: AWS ${s3Key}:${signature}"
  • 相关阅读:
    最近学习的情况
    0Day – 2011.1.12[From B4A]考试终于完了
    PHP 在NetBeans中的测试[转自NetBeans.org]
    12月武汉下雪了
    Delphi下指针使用总结
    0Day – 2010.12.27[转自B4A]
    AQTime教程
    C #define理解
    C 环境的搭配
    数据结构 字符串的模式匹配
  • 原文地址:https://www.cnblogs.com/landhu/p/6482801.html
Copyright © 2020-2023  润新知