Qiniu cloud storage C # example C # Notes

Source: Internet
Author: User

Recently, you need to upload images of your website to cloud storage. so I found qiniu. see the above SDK... I found that there are few comments in it. at that time, I looked at the top. there are basically no good examples for searching on the Internet. great inconvenience for beginners! Finally, I made some basic examples here, hoping to help beginners.

Step 1. assign a value first. The Code is as follows (you should be able to understand it)

Config. access_key = ""; // AK config. secret_key = ""; // SK bucket = ""; // space Name Domain = ""; // Domain Name

  

Step 2. Upload the File Code as follows:

public static bool PutFile(string path) {            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 = path.Substring(path.LastIndexOf(‘/‘) + 1, path.Length - path.LastIndexOf(‘/‘) - 1);            target.PutFinished += new EventHandler<CallRet>((o, e) => {                if (e.OK) {                    flag = true;                }            });            CallRet ret = target.PutFile(upToken, path, key);            return flag;        }

String key = path. substring (path. lastindexof ('/') + 1, path. length-path. lastindexof ('/')-1); // I processed the image. I keep the original image name. The other key is the resource name.

Put so many generations on the previous page in a class. Then you can call it. This is super simple!

The call method is as follows:

Class Name. putfile (savepath) // If static is added, savepath can be directly called, which is the path of the file to be uploaded (local path)

 

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.