标签:style blog http ar io color os sp for
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Qiniu.Conf;
using Qiniu.IO.Resumable;
using System.Collections.Specialized;
using Qiniu.RS;
using Qiniu.RPC;
namespace bootstrapLearn
{
public partial class qiniutest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void bt_ServerClick(object sender, EventArgs e)
{
Qiniu_API.PutFile(ff.Value, Guid.NewGuid().ToString("N") + "aa");
}
}
public static class Qiniu_API
{
public static string Bucket = "";//空间名
public static string Domain = "";//域名
/// <summary>
///
/// </summary>
/// <param name="path">本地路径</param>
/// <param name="fileName">文件名</param>
/// <returns></returns>
public static bool PutFile(string path, string fileName)
{
bool flag = false;
Settings putSetting = new Settings();
ResumablePutExtra extra = new ResumablePutExtra();
NameValueCollection nc = new NameValueCollection();
nc.Add("x:username", "qiniu");
extra.CallbackParams = nc;
ResumablePut target = new ResumablePut(putSetting, extra);
string upToken = new PutPolicy(Bucket).Token(new Qiniu.Auth.digest.Mac());
string key = fileName;
target.PutFinished += new EventHandler<CallRet>((o, e) =>
{
if (e.OK)
{
flag = true;
}
});
CallRet ret = target.PutFile(upToken, path, key);
return flag;
}
static Qiniu_API()
{
Config.ACCESS_KEY = ""; //AK
Config.SECRET_KEY = "";//SK
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="qiniutest.aspx.cs" Inherits="bootstrapLearn.qiniutest" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <input type="file" runat="server" id="ff" /> <input type="button" runat="server" value="上传" id="bt" onserverclick="bt_ServerClick" /> </form> </body> </html>

转自: http://www.cnblogs.com/hjwtech/p/3927277.html
标签:style blog http ar io color os sp for
原文地址:http://www.cnblogs.com/bingguang/p/4173169.html