Ejemplo n.º 1
0
        public async Task FetchTest()
        {
            var config = new Config {
                Zone = Zone.ZoneCnEast
            };
            var mac           = new Mac(AccessKey, SecretKey);
            var bucketManager = new BucketManager(mac, config);
            var resUrl        = "http://devtools.qiniu.com/qiniu.png";
            var ret           = await bucketManager.Fetch(resUrl, Bucket, "qiniu-fetch.png");

            if (ret.Code != (int)HttpCode.OK)
            {
                Assert.True(false, "fetch error: " + ret);
            }

            Console.WriteLine(ret.ToString());

            ret = await bucketManager.Fetch(resUrl, Bucket, null);

            if (ret.Code != (int)HttpCode.OK)
            {
                Assert.True(false, "fetch error: " + ret);
            }

            Console.WriteLine(ret.ToString());
        }
Ejemplo n.º 2
0
        public void FetchTest()
        {
            Mac           mac    = new Mac(AccessKey, SecretKey);
            BucketManager target = new BucketManager(mac);

            HttpResult result = target.Fetch(TestURL1, Bucket1, FileKey1);

            bool cond = (result.Code == (int)HttpCode.OK ||
                         result.Code == (int)HttpCode.BUCKET_NOT_EXIST ||
                         result.Code == (int)HttpCode.FILE_EXISTS);

            Assert.IsTrue(cond);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 拉取资源到空间
        /// </summary>
        public static void fetch()
        {
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);

            string bucket    = "test";
            string saveKey   = "1.jpg";
            string remoteUrl = "http://remote-url.com/file-name";

            BucketManager bm = new BucketManager(mac);

            var result = bm.Fetch(remoteUrl, bucket, saveKey);

            Console.WriteLine(result);
        }
Ejemplo n.º 4
0
        public void FetchTest()
        {
            Config config = new Config();

            config.Zone = Zone.ZONE_CN_East;
            Mac           mac           = new Mac(AccessKey, SecretKey);
            BucketManager bucketManager = new BucketManager(mac, config);
            string        resUrl        = "http://devtools.qiniu.com/qiniu.png";
            FetchResult   ret           = bucketManager.Fetch(resUrl, Bucket, "qiniu-fetch.png");

            if (ret.Code != (int)HttpCode.OK)
            {
                Assert.Fail("fetch error: " + ret.ToString());
            }
            Console.WriteLine(ret.ToString());

            ret = bucketManager.Fetch(resUrl, Bucket, null);
            if (ret.Code != (int)HttpCode.OK)
            {
                Assert.Fail("fetch error: " + ret.ToString());
            }
            Console.WriteLine(ret.ToString());
        }
Ejemplo n.º 5
0
    public FetchInfo FetchUpload(string targetUrl, string key)
    {
        var config = new Qiniu.Storage.Config {
            Zone = _zone
        };
        var bm     = new BucketManager(_mac, config);
        var result = bm.Fetch(targetUrl, _options.Bucket, key);

        if (result.Code != 200)
        {
            throw new HttpRequestException("自动存储图片失败!" + result.Text ?? result.RefText);
        }
        return(result.Result);
    }
Ejemplo n.º 6
0
        public FetchInfo FetchUpload(string targetUrl, string key)
        {
            var config = new Config {
                Zone = _zone
            };

            var bm = new BucketManager(_mac, config);

            //var fetchUrl = string.Format("{0}{1}",
            //    config.IovipHost(_mac.AccessKey, _options.Bucket), bm.FetchOp(targetUrl, _options.Bucket, key));

            var result = bm.Fetch(targetUrl, _options.Bucket, key);

            if (result.Code != 200)
            {
                throw new HttpRequestException("调用七牛云抓取并存储文件失败!" + result.Text ?? result.RefText);
            }
            return(result.Result);
        }