七牛雲端儲存 上傳 C# asp.net

來源:互聯網
上載者:User

標籤: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

 

七牛雲端儲存 上傳 C# asp.net

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.