码迷,mamicode.com
首页 > Windows程序 > 详细

七牛云存储 上传 C# asp.net

时间:2014-12-19 10:00:20      阅读:1886      评论:0      收藏:0      [点我收藏+]

标签: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>

bubuko.com,布布扣

 

转自:  http://www.cnblogs.com/hjwtech/p/3927277.html

 

七牛云存储 上传 C# asp.net

标签:style   blog   http   ar   io   color   os   sp   for   

原文地址:http://www.cnblogs.com/bingguang/p/4173169.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!