C 對七牛雲的操作

2022-02-23 16:44:30 字數 3644 閱讀 5350

1.配置環境

專案中引用 qiniu.4.0.dll

在webconfig:

//賬號 ---> 金鑰ak

//賬號 ---> 金鑰sk

2.建立七牛檔案的實體類

public class qiniufile

public string filekey

public string filemime

public string filethumbnailurl

}3.頁 面html 用的form 提交

@* 載入七牛雲的資料 *@

@* 上傳的效果*@

" + result[i].filekey + "

";} else

}$("#filelist").html(filehtml);

},error: function (ex)

});}

};5.controller:

public class uploadpushmanagecontroller : basecontroller

#region new 20151230 wyh

///

/// 上傳檔案

///

/// 使用者七牛的空間[現在預設]

///

public actionresult uploadfile(string domain)

else;}

//給使用者在資料中新增記錄

= user.pid;

= user.uid;

= file.contentlength;

//icm_usercloud usercloudold = momange.getusercloudbyuserid(user.uid);

if (usercloudold != null);}

else

}else;}

else

}if (!isfull)

else}}

return result;

}///

/// 載入使用者在七牛所有檔案

///

/// 使用者在七牛的空間

///

public actionresult initpagedate(string qiniudomain = null)

filelist.add(file);

}result.data = filelist;

return result;

}///

/// 檢視檔案

///

/// 檔名

///

///

///

///

///

///

public actionresult deletefile(string filename, string qiniudomain = null)

return result;

}///

/// 推送檔案

///

/// 檔名

///

///

/// 檔名

/// 檔案流

/// 使用者的七牛空間

///

public static bool putfile(string key, stream stream, string domain = null)

putpolicy policy = new putpolicy(domain, 3600);

string uptoken = policy.token();

putextra extra = new putextra();

ioclient client = new ioclient();

putret ret = client.put(uptoken, key, stream, extra);

if (ret.ok)

else

}///

/// 斷點續傳

///

/// 使用者的七牛空間

/// 檔案key

///

/// 可以通過註冊resumableputextra以下兩個事件監聽當前上傳進度以及成功情況:

public event eventhandlernotify;

public event eventhandlernotifyerr;

public static void resumableputfile(string domain, string key, string fname = null)

///

/// 列出所有檔案資訊

///

/// 使用者七牛空間

/// 檔名

/// 私有/公開

/// 空間

public static string getfileurl(string key, bool ispublic = false, string domainurl = null)

//公有鏈結

string baseurl = getpolicy.makebaseurl(domainurl, key);

if (ispublic) return baseurl;

//私有鏈結

string private_url = getpolicy.makerequest(baseurl);

return private_url;

}///

/// 刪除單個檔案

///

/// 檔名

/// 檔案所在使用者的空間名

public static bool delete(string key, string qiniudomain = null)

rsclient client = new rsclient();

callret ret = client.delete(new entrypath(qiniudomain, key));

if (ret.ok)

else

}///

///  視屏縮圖

///

/// 輸出的目標截圖格式,支援jpg、png

/// 縮圖寬度,單位:畫素(px),取值範圍為1-3840。

/// 縮圖高度,單位:畫素(px),取值範圍為1-2160。

/// 指定順時針旋轉的度數,可取值為90、180、270、auto,預設為不旋轉。 //預設不旋轉[可以選擇]

///

public static string thumbnailurl(string filekey, string vframe = null, string offset = null, string width = null, string height = null, string domain = null)

/offset//w//h",vframe,offset,width,height);

string thumbnailurl = getfileurl(filekey, true, domain) + thumbnail;

return thumbnailurl;

}///

/// 初始化七牛,讀取webconfig

///

public static void initqiniu()}}

七牛雲儲存

總共100分,選擇5 5,填空5 5 問答程式設計5 10 選擇主要知識點 1.二叉樹遍歷 已知前,後序遍歷求不可能的中序遍歷 2.查詢 3.大根堆 4.網路 tcp udp等 5.圖,乙個有五個頂點的圖,要去掉多少條邊才能生成樹 填空 1.數列找規律 2.求概率 磁碟丟檔案概率計算 3.aba b...

七牛雲 qshell 的用法

qshell user ls qshell user cu 504996366 qq.com qshell listbucket2 start 2018 10 30 end 2018 11 30 pt shop test o pt shop test.date.list.txt 執行這句會生成乙個檔...

七牛雲面經

2018 3 28 1 c 過載和重寫的區別 2 說說c 的型別安全機制 3 你的專案裡面是將模組封裝成了動態庫,為什麼用動態庫不用靜態庫。分別從使用 編譯 作業系統角度說說動態庫和靜態庫的區別。4 讓你實現乙個vector,要注意哪些細節 5 程序和執行緒的區別,為什麼有了程序還要執行緒,你的專案...