Code
Ossclient; string bucketname = "hd3p"; Public void processrequest (httpcontext context) {context. response. contenttype = "application/JSON; charset = UTF-8"; httppostedfile imgfile = context. request. files ["filedata"]; If (imgfile! = NULL) {string accessid = "ut5hhgas69gkf3jt"; // accessid string accesskey = "secret"; // accesskey ossclient = new aliyun. openservices. openstorageservice. ossclient (accessid, accesskey); // Of course, objectmetadata meta = new objectmetadata (); Meta. contenttype = "image/JPEG"; string key = "PIC/" + imgfile. filename; putobjectresult result = ossclient. putobject (bucketname, Ke Y, imgfile. inputstream, Meta); // upload the image accesscontrollist ACCS = ossclient. getbucketacl (bucketname); string imgurl = string. Empty; If (! ACCS. grants. any () // determine whether you have read permission {imgurl = ossclient. generatepresigneduri (bucketname, key, datetime. now. addminutes (5 )). absoluteuri; // generate a signed URI valid for 5 minutes} else {imgurl = string. format ("http: // {0} .oss.aliyuncs.com/#1}", bucketname, key);} context. response. write (string. format ("{0} | {1} | {2} | {3}", imgurl, key ));//}}
Source code