public String uploadImg(ImgFileMsg item) { String key = item.name; //todo 添加日期 //添加文件后缀 //Regex regex = new Regex(@"\.(jpg|jpeg|bmp|png)"); Regex regex = Setting.getRegexForType(); String str = regex.Match(item.path).Value; if (str != "") { key = dateStr + item.name + str; } else { Console.WriteLine("不支持的文件格式"); return(null); } //覆盖上传 PutPolicy put = new PutPolicy(bucket + ":" + key, 3600); //调用Token()方法生成上传的Token string upToken = put.Token(); PutRet ret = target.PutFile(upToken, key, item.path, extra); //todo 上传成功的反馈 //MessageBox.Show(ret.key.ToString()); return(Setting.qiniuUrl + ret.key.ToString()); }
/// <summary> /// 读取文件信息并提取需要上传的附件信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void panel1_DragDrop(object sender, DragEventArgs e) { //完整的文件路径 String pathStr = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); setHint("准备读取文件:" + pathStr); //文件路径 fileManage.setTextFilePath(pathStr); //显示文本内容 rtb_main.Text = fileManage.getTextFileText(); tB_title.Text = System.IO.Path.GetFileNameWithoutExtension(pathStr); Regex regex = new Regex(@"!\[(?<name>.*?)\]\((?<path>.*?)\)"); MatchCollection matches = regex.Matches(fileManage.getTextFileText()); foreach (Match match in matches) { GroupCollection gc = match.Groups; ImgFileMsg item = new ImgFileMsg(gc["name"].Value, gc["path"].Value); fileManage.addImgItem(item); } setHint("找到 " + matches.Count + " 份附件"); panel1.Visible = false; }
/// <summary> /// 添加需要上传的文件名以及文件路径 /// </summary> /// <param name="item"></param> public void addImgItem(ImgFileMsg item) { imgList.Add(item); }