如何使用vbscript上传图像(POST)?

时间:2019-04-15 13:56:57

标签: vbscript

我正在使用Jira API,需要使用VBScript将图像上传到票证中。

我在StackOverflow上找到了这段代码,但是我无法使其适应我的用例

Dim restReq, url, auth

Set restReq = CreateObject("Msxml2.ServerXMLHTTP.6.0")

url = "https://mysite/jira/rest/api/2/issue/AAA-15/attachments"

sBoundary = "-ooo-"
contentType ="multipart/form-data"
auth = "Basic AAAaaa1234---fgtrg=="
restReq.open "POST", url, false
restReq.SetRequestHeader "Authorization", auth
restReq.SetRequestHeader "Content-Type", contentType
restReq.SetRequestHeader "Accept", "application/json"
restReq.SetRequestHeader "Content-Disposition","form-data; name='file'; filename='test.png'"
restReq.SetRequestHeader "X-Atlassian-Token","no-check"
restReq.SetRequestHeader "Content-Type","multipart/form-data; boundary="+ sBoundary 
restReq.SetRequestHeader "Content-Transfer-Encoding","base64"
inByteArray = readBytes("test.png")
base64Encoded = encodeBase64(inByteArray)
restReq.send

WScript.echo restReq.responseText


Private function readBytes(file)
  dim inStream
  ' ADODB stream object used
  set inStream = WScript.CreateObject("ADODB.Stream")
  ' open with no arguments makes the stream an empty container 
  inStream.Open
  inStream.type= 1
  inStream.LoadFromFile(file)
  readBytes = inStream.Read()
end function

Private function encodeBase64(bytes)
  dim DM, EL
  Set DM = CreateObject("Microsoft.XMLDOM")
  ' Create temporary node with Base64 data type
  Set EL = DM.createElement("tmp")
  EL.DataType = "bin.base64"
  ' Set bytes, get encoded String
  EL.NodeTypedValue = bytes
  encodeBase64 = EL.Text
end function

对于命令“ restReq.responseText”,我希望具有JSON,但我什么也没有:[]。

您能帮我找到错误的地方吗?

谢谢。

0 个答案:

没有答案