C # upload and download files using seven Cow cloud storage

Source: Internet
Author: User

Projects need to upload audio and video files to the server, considering the high concurrency requirements, through the seven cows to achieve.

Directly on the code

usingQiniu.io;usingQiniu.IO.Resumable;usingQiniu.rpc;usingqiniu.rs;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceqiniutest{/// <summary>    ///There are two ways of uploading files:///one is the ordinary way through balls files, referred to as ordinary upload; ///Another way is to continue to upload breakpoints, breakpoints continue to upload in the network conditions are very general can also have excellent upload speed, and the transmission of large files is very friendly. /// </summary>    classProgram {Static voidMain (string[] args) {Qiniu.Conf.Config.ACCESS_KEY="6qq7cnz4bljdkqowq5uoahevcad0bca7tc5xxxxx"; Qiniu.Conf.Config.SECRET_KEY="9rugnbftvm-plwczeor6ed9mujz4bkitf7yxxxxx"; stringBucket ="CVTEHRMXZ"; stringFilekey ="Application System Panorama map. PNG";            Getfilestat (bucket, filekey); //small file through balls            stringFileName ="Business function architecture diagram-im and enterprise. jpg"; Putfile (Bucket, Guid.NewGuid (). ToString ()+ FileName,"d:\\"+fileName); //file uploads in ASP.//resumableputfile (Bucket, Guid.NewGuid ().            ToString (), Path.Combine (Path, request.form[0])); //Large File Upload//string bigfilename = "Eclipse-java-luna-sr1-win32-x86_64.zip"; //resumableputfile (Bucket, Guid.NewGuid (). ToString () + bigfilename, "d:\\software\\" + bigfilename);GetFile ("7xxxxx.com1.z0.glb.clouddn.com", Filekey); }        /// <summary>        ///View individual file property information/// </summary>        /// <param name= "Bucket" >Seven Cow cloud storage space name</param>        /// <param name= "key" >file key, which is the filename</param>         Public Static voidGetfilestat (stringBucketstringkey) {rsclient Client=Newrsclient (); Entry Entry= client. Stat (NewEntrypath (bucket, key)); if(entry. OK) {Console.WriteLine ("Hash:"+entry.                Hash); Console.WriteLine ("fsize:"+entry.                Fsize); Console.WriteLine ("Puttime:"+entry.                Puttime); Console.WriteLine ("MimeType:"+entry.                MimeType); Console.WriteLine ("Customer:"+entry.            Customer); }            Else{Console.WriteLine ("Failed to Stat"); }        }        /// <summary>        ///Delete a single file/// </summary>        /// <param name= "Bucket" >the space name where the file resides</param>        /// <param name= "key" >file Key</param>         Public Static voidDelete (stringBucketstringkey) {Console.WriteLine ("\n===> Delete {0}:{1}", bucket, key); Rsclient Client=Newrsclient (); Callret ret= client. Delete (NewEntrypath (bucket, key)); if(ret. OK) {Console.WriteLine ("Delete OK"); }            Else{Console.WriteLine ("Failed to delete"); }        }        /// <summary>        ///Delete files in bulk/// </summary>        /// <param name= "Bucket" >the space name where the file resides</param>        /// <param name= "Keys" >file Key</param>         Public Static voidBatchdelete (stringBucketstring[] keys) {rsclient Client=Newrsclient (); List<EntryPath> entrypaths =NewList<entrypath>(); foreach(stringKeyinchkeys) {Console.WriteLine ("\n===> Stat {0}:{1}", bucket, key); Entrypaths.add (NewEntrypath (bucket, key)); } client.        Batchdelete (Entrypaths.toarray ()); }        /// <summary>        ///normal way through balls file/// </summary>        /// <param name= "Bucket" >the space name where the file resides</param>        /// <param name= "key" >You can define your own file key, general GUID</param>        /// <param name= "fname" >file path + file name</param>         Public Static voidPutfile (stringBucketstringKeystringfname) {            varPolicy =NewPutpolicy (Bucket,3600); stringUptoken =policy.            Token (); PutExtra Extra=NewPutExtra (); Ioclient Client=Newioclient (); Client.        Putfile (Uptoken, Key, fname, extra); }        /// <summary>        ///The extension of the breakpoint, upload large files in this way/// </summary>        /// <param name= "Bucket" >the space name where the file resides</param>        /// <param name= "key" >You can define your own file key, general GUID</param>        /// <param name= "fname" >file path + file name</param>         Public Static voidResumableputfile (stringBucketstringKeystringfname) {Console.WriteLine ("\n===> resumableputfile {0}:{1} fname:{2}", bucket, key, fname); Putpolicy Policy=NewPutpolicy (Bucket,3600); stringUptoken =policy.            Token (); Settings setting=NewSettings (); Resumableputextra Extra=NewResumableputextra (); Resumableput Client=Newresumableput (setting, extra); Client. Putfile (Uptoken, fname, Guid.NewGuid ().        ToString ()); }        /// <summary>        ///Get file by Get method/// </summary>        /// <param name= "domain" >file Fields</param>        /// <param name= "key" >file Key</param>         Public Static voidGetFile (stringDomainstringkey) {System.Diagnostics.Process.Start ("/ http"+ domain +"/"+key); }    }}

C # upload and download files using seven Cow cloud storage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.