華爲雲服務(HWClouds)之對象存儲服務試用

華爲對象存儲服務通過簡單的web services接口提供對象存儲能力,目前只提供C#、Java、PHP、Python語言的SDK。

首先註冊華爲雲帳號,然後開通對象存儲服務,讓人不爽的是,開通之前你至少要往你的帳戶預存100元。。。

然後,新建存儲空間


對於存儲空間的權限設置在這裏


然後可以在存儲空間下面新建文件夾或者直接上傳文件


然後上傳文件

之後可以通過界面對文件的讀寫權限進行管理


當然,你也可以一鍵公開,然後把生成的url發給你的朋友就好了。


除了在界面上操作,你也可以通過SDK去操作。這裏用C#測試,首先將SDK裏面的幾個dll引用到項目裏面。


下面是簡單的下載文件演示代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using com.hws.s3.client;
using com.hws.s3.models;
using com.hws.s3.response;
using com.hws.s3.utils;
using System.IO;

namespace HWSS3CSharpTest
{
    public partial class Form1 : Form
    {
        public static String AK = "YourAK";
        public static String SK = "YourSK";
        public static String Server = "s3.hwclouds.com";
        public String testbucket = "objectstorageservicetest";

        public HuaweiS3 s3 = new HuaweiS3(AK, SK, false);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Stream stream = s3.getObject(testbucket, "dirtest/testfile.docx").m_pobject.stream;
            FileStream rdr = new FileStream(@"testdownloadfile.docx", FileMode.OpenOrCreate, FileAccess.Write);

            byte[] inData = new byte[4096];
            int bytesRead = stream.Read(inData, 0, inData.Length);

            while (bytesRead > 0)
            {
                rdr.Write(inData, 0, bytesRead);
                bytesRead = stream.Read(inData, 0, inData.Length);
            }
            rdr.Close();
            stream.Close();
        }
    }
}

你也可以通過web界面瞭解對象存儲服務的容量使用情況、流量使用情況、請求數統計。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章