C # realizes seven Cow cloud storage

Source: Internet
Author: User

Cloud storage is to store local resource files on the network, which can be accessed by public network. Equivalent to the function of the network disk, feel very convenient.

This is the seven cow cloud storage. Interested can go to the official website for a detailed view

According to the official website of the introduction, itself is to provide the SDK, we can according to their own development of the application, download the corresponding SDK package. I downloaded the C # version, referring to the corresponding API documentation, will find the latest SDK source code and API documentation inconsistencies. Yes, the document has not been updated in time

So, I'm here to reseal a layer and call it directly. The code is as follows

Define several properties first (when registering seven KN users, issued by the system)

public static string AccessKey = null;    public static string secretkey = null;    public static string Bucket = null; public static string URLPrefix {get; set;}

Uploading files

 public static void UploadFile (string localfile, String savekey) {            Upload strategy Putpolicy putpolicy = new Putpolicy ();            Set the target space to upload putpolicy.scope = Qiniuutil.bucket;            Expiration time of the upload policy (in seconds) putpolicy.setexpires (3600);            After the file has been uploaded, the number of days after the//putpolicy.deleteafterdays = 1 is automatically deleted; Generate upload Voucher//reference address: https://segmentfault.com/q/1010000008205978 string jsonparam = Jsonhelper.getjsonby            Object (Putpolicy);            Mac Mac = new Mac (Qiniuutil.accesskey, Qiniuutil.secretkey);            String uploadtoken = Auth.createuploadtoken (Mac, Jsonparam);            Formuploader UpLoader = new Formuploader (false);            Httpresult result = Uploader.uploadfile (LocalFile, Savekey, Uploadtoken); if (result. Code! =) {throw new Exception (result.            Reftext);        } return; }

  

Download file

        public static void DownloadFile (string url, string localfilefullname)        {            //File Link address:/http oio2cxdal.bkt.clouddn.com/1/20170213231810.jpg            downloadmanager.download (URL, localfilefullname);        }

deleting files

        public static void DeleteFile (string savekey)        {            mac Mac = new Mac (Qiniuutil.accesskey, Qiniuutil.secretkey);            Bucketmanager BM = new Bucketmanager (MAC);            Bm. Delete (Qiniuutil.bucket, Savekey);        }

There are other methods in the SDK, such as the continuation of the breakpoint, such as, if necessary, can continue to encapsulate

More simple calling Code

    Qiniuutil.accesskey = "";    Qiniuutil.secretkey = "";    Qiniuutil.bucket = "";    Qiniuutil.urlprefix = "";        String savekey = @ "1/20170213231810.jpg";        (OK) upload file    //string localfile = @ "D:\TestImage2.jpg";                Qiniuutil.uploadfile (LocalFile, savekey);        (OK) download file    //string LocalFile = @ "D:\111.jpg";    Qiniuutil.downloadfile ("Http://oio2cxdal.bkt.clouddn.com/1/20170213231810.jpg", LocalFile);        (OK) Delete file    qiniuutil.deletefile (Savekey);

  

It is important to note that seven cattle will be assigned to the server according to the region, that is, if you are in South China, you can not make the East China server operation. Here to modify the next source, the location is as follows

No source code, directly call the method Config.setzone can

Picture address of the seven cows

Look, isn't so easy

C # realizes 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.