Пример #1
0
        public string UpLoadFile()
        {
            #region params
            string bucketName=string.Empty;
            string key = string.Empty;
            string localFile = string.Empty;
            string bigkey = string.Empty;
            string bigFile = string.Empty;
            string DOMAINName = string.Empty;
            Client conn;
            RSService rs;
            #endregion params

            if (context.Request["key"] == null)
            { return string.Concat(new[] { jsonCallback, "({\"errorMessage\":\"参数不正确\"})" }); }
            else
            { key = context.Request["key"]; }
            //万一能取到全地址
            if (key.IndexOf('\\') > 0)
            {
                key = key.Substring(key.LastIndexOf('\\'));
            }
            //公有秘钥
            Config.ACCESS_KEY = "b4Tb1AzHnH0xHLqAeLBMg9MGAw2IBaDgqo47zuUu";
            //私有秘钥
            Config.SECRET_KEY = "ZVD00fr92pv-0-o8dTk2N7lxxs1g0s54SYCsbhEi";
            bucketName = "sean1194";
            //放置的域名
            DOMAINName = bucketName + ".qiniudn.com";

            //获得签名认证
            conn = new DigestAuthClient();
            // 签名认证完成后,即可使用该认证来新建资源表
            rs = new RSService(conn, bucketName);
            //这句话最好在上传下载之前执行一遍,恐drop了之后会更改
            CallRet callRet = rs.MkBucket();

            string entryUrl = QBox.Util.Base64UrlSafe.Encode(bucketName + ":" + key);
            var authPolicy = new AuthPolicy(bucketName, 3600);
            string upToken = authPolicy.MakeAuthTokenString();

            string ret = "{"
                    + "bucketName : "
                    + bucketName
                    + ",key: "
                    + key
                    + ",DOMAINName : "
                    + DOMAINName
                    + ",upToken: "
                    + upToken
                    + ",entryUrl : "
                    + entryUrl
                    + "}";
            return ret;
        }
Пример #2
0
        public static void RSClientPutFile()
        {
            Console.WriteLine("\n==> PutAuth");
            PutAuthRet putAuthRet = rs.PutAuth();
            PrintRet(putAuthRet);
            if (putAuthRet.OK)
            {
                Console.WriteLine("Expires: " + putAuthRet.Expires.ToString());
                Console.WriteLine("Url: " + putAuthRet.Url);
            }
            else
            {
                Console.WriteLine("Failed to PutAuth");
            }

            Console.WriteLine("\n===> RSClient.PutFile");
            PutFileRet putFileRet = RSClient.PutFile(putAuthRet.Url, bucketName, key, null, localFile, null, "key=<key>");
            PrintRet(putFileRet);
            if (putFileRet.OK)
            {
                Console.WriteLine("Hash: " + putFileRet.Hash);
            }
            else
            {
                Console.WriteLine("Failed to RSClient.PutFile");
            }

            Console.WriteLine("\n===> Generate UpToken");
            var authPolicy = new AuthPolicy(bucketName, 3600);
            string upToken = authPolicy.MakeAuthTokenString();
            Console.WriteLine("upToken: " + upToken);

            Console.WriteLine("\n===> RSClient.PutFileWithUpToken");
            putFileRet = RSClient.PutFileWithUpToken(upToken, bucketName, key, null, localFile, null, "key=<key>");
            PrintRet(putFileRet);
            if (putFileRet.OK)
            {
                Console.WriteLine("Hash: " + putFileRet.Hash);
            }
            else
            {
                Console.WriteLine("Failed to RSClient.PutFileWithUpToken");
            }
        }
Пример #3
0
        public static void RSClientPutFileWithCRC32()
        {
            Console.WriteLine("\n===> RSClientPutFileWithCRC32 Generate CRC32");
            UInt32 crc = CRC32.CheckSumFile(localFile);
            Console.WriteLine("CRC32: " + crc.ToString());

            Console.WriteLine("\n===> RSClientPutFileWithCRC32 Generate UpToken");
            var authPolicy = new AuthPolicy(bucketName, 3600);
            string upToken = authPolicy.MakeAuthTokenString();
            Console.WriteLine("upToken: " + upToken);

            Console.WriteLine("\n===> RSClient.PutFileWithUpToken(CRC32)");
            PutFileRet putFileRet = RSClient.PutFileWithUpToken(upToken, bucketName, key, null, localFile, null, "key=<key>", crc);
            PrintRet(putFileRet);
            if (putFileRet.OK)
            {
                Console.WriteLine("Hash: " + putFileRet.Hash);
            }
            else
            {
                Console.WriteLine("Failed to RSClient.PutFileWithUpToken(CRC32)");
            }
        }
Пример #4
0
 public static void ResumablePutFile()
 {
     Console.WriteLine("\n===> ResumablePut.PutFile");
     var authPolicy = new AuthPolicy(bucketName, 3600);
     string upToken = authPolicy.MakeAuthTokenString();
     PutAuthClient client = new PutAuthClient(upToken);
     PutFileRet putFileRet = ResumablePut.PutFile(client, bucketName, bigkey, null, bigFile, null, "key=<key>");
     PrintRet(putFileRet);
     if (putFileRet.OK)
     {
         Console.WriteLine("Hash: " + putFileRet.Hash);
     }
     else
     {
         Console.WriteLine("Failed to ResumablePut.PutFile");
     }
 }