博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.net core webapi 转成数据流
阅读量:5873 次
发布时间:2019-06-19

本文共 3464 字,大约阅读时间需要 11 分钟。

hot3.png

最近在使用ueditor时,调取后端配置文件,之前是asp.net的官方已有案例

现在转为 webapi时,需要将配置文件转成response数据流

一般我们使用webapi时,都是将数据转换成一个实体或者string来输出,这些方式都无法使用与ueditor调用后台配置文件的方式

ueditor从服务器返回的是一段javascript脚本,代码如下

bd__editor__89sg27({"imageActionName":"uploadimage","imageFieldName":"upfile","imageMaxSize":2048000,"imageAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp"],"imageCompressEnable":true,"imageCompressBorder":1600,"imageInsertAlign":"none","imageUrlPrefix":"http://image.keesoft.cn/api/ueditor/","imagePathFormat":"upload/image/{yyyy}{mm}{dd}/{time}{rand:6}","scrawlActionName":"uploadscrawl","scrawlFieldName":"upfile","scrawlPathFormat":"upload/image/{yyyy}{mm}{dd}/{time}{rand:6}","scrawlMaxSize":2048000,"scrawlUrlPrefix":"/ueditor/net/","scrawlInsertAlign":"none","snapscreenActionName":"uploadimage","snapscreenPathFormat":"upload/image/{yyyy}{mm}{dd}/{time}{rand:6}","snapscreenUrlPrefix":"/ueditor/net/","snapscreenInsertAlign":"none","catcherLocalDomain":["127.0.0.1","localhost","img.baidu.com"],"catcherActionName":"catchimage","catcherFieldName":"source","catcherPathFormat":"upload/image/{yyyy}{mm}{dd}/{time}{rand:6}","catcherUrlPrefix":"/ueditor/net/","catcherMaxSize":2048000,"catcherAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp"],"videoActionName":"uploadvideo","videoFieldName":"upfile","videoPathFormat":"upload/video/{yyyy}{mm}{dd}/{time}{rand:6}","videoUrlPrefix":"/ueditor/net/","videoMaxSize":102400000,"videoAllowFiles":[".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".wav",".mid"],"fileActionName":"uploadfile","fileFieldName":"upfile","filePathFormat":"upload/file/{yyyy}{mm}{dd}/{time}{rand:6}","fileUrlPrefix":"/ueditor/net/","fileMaxSize":51200000,"fileAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp",".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".wav",".mid",".rar",".zip",".tar",".gz",".7z",".bz2",".cab",".iso",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pdf",".txt",".md",".xml"],"imageManagerActionName":"listimage","imageManagerListPath":"upload/image","imageManagerListSize":20,"imageManagerUrlPrefix":"/ueditor/net/","imageManagerInsertAlign":"none","imageManagerAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp"],"fileManagerActionName":"listfile","fileManagerListPath":"upload/file","fileManagerUrlPrefix":"/ueditor/net/","fileManagerListSize":20,"fileManagerAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp",".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".wav",".mid",".rar",".zip",".tar",".gz",".7z",".bz2",".cab",".iso",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pdf",".txt",".md",".xml"]})

所以webapi必须以同样的方式返回javascript脚本,所有webapi只能通过输出文本流来解决这个问题

[HttpGet][Route("Test")]public async Task Test(string actionType, string callback)        {            Response.ContentType = "application/javascript";            string strPath = Path.Combine(Directory.GetCurrentDirectory()) + @"\config.json";            StreamReader sr = new StreamReader(strPath);            string strText = sr.ReadToEnd();            sr.Close();            object json = Newtonsoft.Json.JsonConvert.DeserializeObject(strText);            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(callback + "(" + Newtonsoft.Json.JsonConvert.SerializeObject(json) + ")");            await Response.Body.WriteAsync(bytes, 0, bytes.Length);        }

 

转载于:https://my.oschina.net/kee1986/blog/3008805

你可能感兴趣的文章
socket和http间的区别
查看>>
error笔记
查看>>
C++——流类库和输入/输出
查看>>
Windows下动态库的制作与使用
查看>>
STL容器简介
查看>>
会写"helloworld",不等于入门
查看>>
element-ui table多选CheckBox参数解析
查看>>
重置mysql的root用户密码
查看>>
隔离级别
查看>>
选项卡实现
查看>>
翻译:理解TCP/IP网络栈&编写网络应用(上)
查看>>
算法导论6:排序小结和最值取法 2016.1.6
查看>>
Delphi线程类(四)
查看>>
使用skin++进行MFC界面美化范例
查看>>
使用httpwatch抓包
查看>>
LeetCode - Best Time to Buy and Sell
查看>>
cross validation交叉验证
查看>>
<、>&、<& 重定向符
查看>>
PHP json_encode 文本形式数字下标数组导致下标丢失
查看>>
【Java】字节流-从文件输入,输出到文件
查看>>