/// <summary> /// 查看BlobFile内容 /// </summary> /// <param name="blobName"></param> /// <returns></returns> public ActionResult ViewBlob(string blobName) { if (blobName == "") { return(Content("无内容")); } ViewBag.FileUrl = AzureBlobHelper.GetSAS(blobName); //ViewBag.FileType = blobName.Split('.').LastOrDefault().ToLower() == "pdf" ? "pdf": "img"; return(View()); //可以下载文本形式 //string text; //using (var memoryStream = new MemoryStream()) //{ // blockBlob2.DownloadToStream(memoryStream); // text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray()); //} }
public ActionResult PostPicture(FormCollection form) { //向BIM上传model string uploadLicenceUri = ""; var file = Request.Files["licencePicture"]; //var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { string filehouzhui = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1, file.FileName.Length - file.FileName.LastIndexOf('.') - 1); if (filehouzhui.ToLower() == "jpg" || filehouzhui.ToLower() == "png" || filehouzhui.ToLower() == "jpeg") { System.Guid addToTheEnd = System.Guid.NewGuid(); string fileRealName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); string fileNameValue = fileRealName + addToTheEnd + "." + filehouzhui; Stream uploadStream = file.InputStream; //上传至Azure string containername = ConfigurationManager.AppSettings["ContainerName"].ToString(); var container = AzureBlobHelper.GetContainer(containername); CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileNameValue); blockBlob.Properties.ContentType = "application/octet-stream"; blockBlob.UploadFromStream(uploadStream); var fileBlobUrl = AzureBlobHelper.GetSAS(fileNameValue).Split('?').FirstOrDefault(); ////文件名的key和value //string savePath = Server.MapPath("~/upload/BusinessLicencePicture"); //if (!System.IO.Directory.Exists(savePath)) //{ // System.IO.Directory.CreateDirectory(savePath); // //加访问权限 // // AddpathPower(savePath, "Users"); //} ////防止文件名重复 //System.Guid addToTheEnd = System.Guid.NewGuid(); //string fileRealName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); //string filepath = savePath + "\\" + fileRealName + addToTheEnd + "." + filehouzhui; //file.SaveAs(filepath); uploadLicenceUri = fileBlobUrl; return(Json(new { Result = true, Message = uploadLicenceUri })); } else { return(Json(new { Result = false, Message = "请上传正确格式的图片文件!" })); } } else { return(Json(new { Result = false, Message = "请上传jpg或jpeg格式的图片!" })); //InfoAllRight = false; //backMessage = backMessage + "上传图片有误/n"; } }