godvan_个人页

个人头像照片 godvan
0
1
0

个人介绍

暂无个人介绍

擅长的技术

获得更多能力
通用技术能力:

暂时未有相关通用技术能力~

云产品技术能力:

暂时未有相关云产品技术能力~

阿里云技能认证

详细说明
暂无更多信息
正在加载, 请稍后...
暂无更多信息
  • 回答了问题 2013-08-06

    如何实现ASP.NET网站程序的上传文件功能。

    Re如何实现ASP.NET网站程序的上传文件功能。
    有木有童鞋做过。能否上传个救命。

    -------------------------

    Re如何实现ASP.NET网站程序的上传文件功能。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Aliyun.OpenServices.OpenStorageService;
    using System.IO;

    public partial class _Default : System.Web.UI.Page
    {
        string accessId = "你的账号";
        string accessKey = "你的密码";
        string bucketName = "你的bucket";


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {

            //文件名
            string key = DateTime.Now.ToString("yyyyMMddHHmmss");


            //string fileToUpload = "file.zip";

            ObjectMetadata metadata = new ObjectMetadata();
            // 可以设定自定义的metadata。
            metadata.ContentType = FileUpload1.PostedFile.ContentType;


            OssClient ossClient = new OssClient(accessId, accessKey);

            using (var fs = FileUpload1.PostedFile.InputStream)
            {

                key  = Path.GetExtension(FileUpload1.PostedFile.FileName);
                //目录处理
                string ml = string.IsNullOrEmpty(Text1.Text) ? "" : Text1.Text.Trim()   "/";
                var ret = ossClient.PutObject(bucketName, ml   key, fs, metadata);

                Label1.Text = ret.ETag;

                string url = string.Format("http://{0}.oss.aliyuncs.com/{1}{2}", bucketName, ml, key);
                Label2.Text = url;


            }
        }
        //删除
        protected void Button2_Click(object sender, EventArgs e)
        {


            OssClient ossClient = new OssClient(accessId, accessKey);

                ossClient.DeleteObject(bucketName, TextBox1.Text);



        }
    }
    踩0 评论0
正在加载, 请稍后...
滑动查看更多
正在加载, 请稍后...
暂无更多信息