uploadFile() public method

上传文件
public uploadFile ( string filePath, string key, string token, Qiniu.Storage.UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler ) : void
filePath string 文件的完整路径
key string 保存在七牛的文件名
token string 上传凭证
uploadOptions Qiniu.Storage.UploadOptions 上传可选设置
upCompletionHandler UpCompletionHandler 上传完成结果处理器
return void
Beispiel #1
0
        public static void uploadWithFop()
        {
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);

            string bucket = "BUCKET";
            string saveKey = "SAVE_KEY";
            string localFile = "LOCAL_FILE";

            // 如果想要将处理结果保存到SAVEAS_BUCKET空间下,文件名为SAVEAS_KEY
            // 可以使用savas参数 <FOPS>|saveas/<encodedUri>
            // encodedUri = StringUtils.urlSafeBase64Encode("SAVEAS_BUCKET" + ":" + "SAVEAS_KEY");
            string fops = "FOPS";

            PutPolicy putPolicy = new PutPolicy();
            putPolicy.Scope = bucket;
            putPolicy.PersistentOps = fops;
            putPolicy.SetExpires(3600);
            putPolicy.DeleteAfterDays = 1;
            string token = Auth.createUploadToken(putPolicy, mac);

            FormUploader fm = new FormUploader();
            fm.uploadFile(localFile, saveKey, token, null, null);
        }
Beispiel #2
0
        public void uploadFileTest()
        {
            //Settings.load();
            Settings.LoadFromFile();
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);
            string key = "test_FormUploaderUploadFile.png";

            FormUploader target = new FormUploader();
            string filePath = "F:\\test.png";

            PutPolicy putPolicy = new PutPolicy();
            putPolicy.Scope = Settings.Bucket;
            putPolicy.SetExpires(3600);
            putPolicy.DeleteAfterDays = 1;
            string token = Auth.createUploadToken(putPolicy, mac);
            UploadOptions uploadOptions = null;

            UpCompletionHandler upCompletionHandler = new UpCompletionHandler(delegate(string fileKey, ResponseInfo respInfo, string response)
            {
                Assert.AreEqual(200, respInfo.StatusCode);
            });
            target.uploadFile(filePath, key, token, uploadOptions, upCompletionHandler);
        }