以文本方式查看主题
- Foxtable(狐表) (http://foxtable.net/bbs/index.asp)
-- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2)
---- 有关调用外部接口如何接收接口文件 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=113552)
|
-- 作者:baoxyang
-- 发布时间:2018/1/18 10:11:00
-- 有关调用外部接口如何接收接口文件
接口输入 #xlsx 格式:
{"success":true,
"tables":"UEsDBBQAAAAIAAAAIQAR0e9YNAoAAIpUAAAYAAAA..." #base64 encoded excel file( base64编码的excel文件)
}
代码: Dim e As RequestEventArgs = args(0)
Dim filepath As String = "d:\\test.jpg"
Dim wb As New weui
Functions.Execute("图片压缩",filepath)
Dim bmp As new Bitmap(filepath)
Dim ms As new System.Io.MemoryStream()
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arr(ms.Length) As Byte
ms.Position = 0
ms.Read(arr, 0, ms.Length)
ms.Close()
Dim strbase64 As String = Convert.ToBase64String(arr)
bmp.dispose
Dim body As String = "{""inputs"":[{""image"":{""dataType"":50,""dataValue"":""" & strbase64 & """},""configure"":
{""dataType"":50,""dataValue"":{""format"":""xlsx"",""finance"":false}}}]}"
Dim appcode As String = "a7846e7bea1d14d848d913287591a4eb2"
Dim req = System.Net.WebRequest.Create("https://form.market.alicloudapi.com/api/predict/ocr_table_parse")
req.Method = "POST"
req.C
req.Headers.Add("Authorization", "APPCODE " & appcode)
Dim aryBuf As Byte() = Encoding.UTF8.GetBytes(body)
req.ContentLength = aryBuf.Length
Dim writer = req.GetRequestStream()
writer.Write(aryBuf, 0, aryBuf.Length)
writer.Close()
writer.Dispose()
Dim pos = req.GetResponse
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
pos.Close
stm.Close
reader.close
可以正常获取str信息 如果把输出存本地文件 以下代码不知道如何增加:请指点!万分感谢!!!
|
-- 作者:baoxyang
-- 发布时间:2018/1/18 10:15:00
--
输出信息内容如下:
|
-- 作者:baoxyang
-- 发布时间:2018/1/18 10:16:00
--
此主题相关图片如下:输出信息.jpg
|
-- 作者:有点甜
-- 发布时间:2018/1/18 10:29:00
--
得到的数据是base64的字符串,转换成文件即可。
如果是保存成图片,代码这样写
Dim str As String = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAB2AFoDASIA AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3 ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA AwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx BhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK U1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3 uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD36iii gAoorlfGXjSz8K2oDgTXcgzHCD+p9BTSbdkB1JIUZNMM8YOC4z9a+f8AU/ib4g1W1khwkEZbJMAI I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mtKXxhDc4GfJG4dTn+dQ24M15DEPvOwUfyrQljOwY6AZNV9OQJq8JwCVdevTNd/MnF jauz6M0ETw2MUO0bBgdc8Y65rYHmjJYMRzjI4qhomH0yF/MjO7GADxnjIrVYtypl+XO0sW6+1eYK UrlB0kmQrcKSgII7YPOK8I8eIV11ISzHaxBB7HNfQMuERv3qDbwRkcGvCvH1sq+LnCurnaCSDkA1 tQdp3BybOKlG2z/3XI/Slt281UJ4IbtUt+mIHK9Mlqi005k29t6/4V26ctyT6A8HErplqQD80Sk5 GO3FdoFBAri/DLNHDbw42hI1GPXiu1H3R9K8tO+o2rMrasxWDIxkV4j4zm+0eI7gjdgIoG7r8wFF Fa0viLhsctMgMmAON2PyrOgQD97j5i+7NFFdkdg+0fSfhrE/h21lVFVyvJA6gVquFVidq4GSBtGO Bnn35oorzyZbj9iEsQg28hc9iK8I8XOZvE8rnA6D9KKK0pfEScTfL+6jHbj+tJpHzzBfVs/rRRXo S/hsZ754ZB8pGZizMckmuyX7o+lFFeWI/9k=" try Dim bs As Byte() = Convert.FromBase64String(str) Dim stream As System.IO.Stream = New System.IO.MemoryStream(bs) Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream) bmp.Save("d:\\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) catch ex As exception msgbox("出错") End try
|
-- 作者:有点甜
-- 发布时间:2018/1/18 10:31:00
--
如果是保存成文件,这样写
Dim str As String = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAB2AFoDASIA AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgE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zyZbj9iEsQg28hc9iK8I8XOZvE8rnA6D9KKK0pfEScTfL+6jHbj+tJpHzzBfVs/rRRXo S/hsZ754ZB8pGZizMckmuyX7o+lFFeWI/9k=" Dim bs() As Byte = Convert.FromBase64String(str) Dim ms As New IO.FileStream("d:\\000.jpg", IO.FileMode.Create) ms.Write(bs, 0,bs.length) ms.close
|
-- 作者:baoxyang
-- 发布时间:2018/1/18 10:32:00
--
有点甜,您好!我想要输出文件(EXcel格式的),而不是图片。我目的是要把我上传图片转换成文字信息的,请指教!!
|
-- 作者:有点甜
-- 发布时间:2018/1/18 10:32:00
--
参考5楼代码
|
-- 作者:baoxyang
-- 发布时间:2018/1/18 12:53:00
--
谢谢!我试试!!
|