"Missing Name Parameter" while uploading image by using API

Hi,

I’m trying to upload image by using the api and postman. But for some resaon by using Postman and my code I get always the error “Missing Name Parameter”.

In postman I have the following headers:
Authorization: Bearer {{access_token}}
Content-Type: image/jpeg

Body:
name: API UPLOAD
files: base64 text value

I really don’t know what is wrong, anybody that can help me?

You will need to pass the ‘name’ parameter as well in your call.

If you leave it empty (as per screenshot below) media name in CMS will be the same as the source file from the hard drive.
If you pass any value in the name parameter then that will be the media name in the CMS.

Side note, we’ve made some changes with how the upload via API is handled, in the next release, you will be able to simply not pass the ‘name’ parameter and it will upload it fine with the original fileName to the CMS.

Thanks for you quick and clear answer. But still I got the same error. This is the json file I sent from my application:
Header:
“Authorization”, “Bearer {{access_token}}”
“Content-Type”, "image/jpeg"
Body:
{“name”: “test.jpeg”,“files”: “/9j/4AAQSkZJRgABAQ…base64 string…”}

Response is:
{“files”:[{“name”:“1505155896-7755.jpeg”,“size”:156365,“type”:“image/jpeg”,“url”:"/api/library?file=1505155896-7755.jpeg&download=1",“error”:“Missing Name Parameter”,“delete_url”:"/api/library?file=1505155896-7755.jpeg",“delete_type”:“DELETE”}]}

I’m doing something wrong, but don’t know what is wrong ;(

Could you give me a screenshot from postman showing you call please?

Does the ‘files’ parameter is set to ‘file’ type like in my screenshot?

Also I realized that I didn’t ask, it is 1.8.2 CMS version, correct?

Sorry for my late response.
I’,m using "Version 1.8.2.
Now I have another error: “Filetype not allowed”.
Settting file or files is making no sense.
This is an example vbscript with the error, do you have any idea how to solve this?

------------------------------------ SCRIPT.vbs ------------------------------------------------------
Public xibo_token, XiboEndpoint, client_id, client_secret, File

'Xibo properties
XiboEndpoint = ""
client_id = ""
client_secret = ""
File = "c:\tmp\1.jpg"

requestXiboToken
AddImageToXibo	
	
Function AddImageToXibo()

	Dim objFileSys
	Dim http
	Dim inByteArray
	Dim base64Encoded
	Dim inFile
	Dim strData

	Set objFileSys = CreateObject("Scripting.FileSystemObject") 
	Set http = CreateObject("Microsoft.XmlHttp")

	Const MULTIPART_BOUNDARY = "------------------B0und4Ry---"
	Const objAuthKey = "MyAuthorizationKey==" 


	'http.onreadystatechange = getRef("HTTPCallback")

	inByteArray = readBytes(File)
	base64Encoded = encodeBase64(inByteArray)
	strData = strData & MULTIPART_BOUNDARY & vbCrLf
	strData = strData & "Content-Disposition: form-data; name=""files""; filename=""test.jpg"""  & vbCrLf 
	strData = strData & "Content-Type: image/jpeg"	& vbCrLf  & vbCrLf
	strData = strData & MULTIPART_BOUNDARY & vbCrLf
	strData = strData & "Content-Disposition: form-data; name=""name""" & vbCrLf & "API UPLOAD"  & vbCrLf & vbCrLf
	strData = strData & MULTIPART_BOUNDARY & vbCrLf
	strData = strData & "Content-Disposition: form-data; name=""files""" & vbCrLf 
	strData = strData & base64Encoded
	strData = strData & vbCrLf
	strData = strData & MULTIPART_BOUNDARY
	
	'msgbox(strData)

	Call http.open("POST", XiboEndpoint & "/library",False) 
	'Call http.setRequestHeader("FT-Authorization","Basic " & objAuthKey)
	Call http.setRequestHeader("Authorization", "Bearer " & xibo_token)
	Call http.setRequestHeader("Content-Type","multipart/form-data; boundary=" & MULTIPART_BOUNDARY )
	'Call http.setRequestHeader("Content-Disposition","form-data; name=""files""; filename=""test.jpg""")
	'Call http.setRequestHeader("Content-Type","image/jpeg")
	Call http.SetRequestHeader("Content-Length", Len(strData))
	Call http.send(strData)

	MsgBox(http.status & ": " & http.responseText)
End Function

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

Function requestXiboToken

	Dim restReq
	Set restReq = CreateObject ("Msxml2.XMLHttp.6.0")
	url =  XiboEndpoint & "/authorize/access_token"
	
	'---- Set url
	restReq.open "POST", url , False
	
	'---- Create headers
	restReq.setRequestHeader "content-type", "application/x-www-form-urlencoded"
	
	'---- Send request
	restReq.send("client_id=" & client_id & "&client_secret=" & client_secret & "&grant_type=client_credentials")
	
	
	'---- Output response
	If Err.Number <> 0 Then  
		WriteLog( "EXCEPTION: Error while getting XiboToken on URL " & url  )
		WriteLog( "EXCEPTION: " & Err & " " & Err.Description)
		Quit
	Else	
		a = Split(restReq.responseText,chr(34))
		xibo_token = a(3)
		
		if(xibo_token = "message") Then
			MsgBox( "EXCEPTION: Getting invalid Xibo token: "& vbNewLine &  restReq.responseText)
			Quit
		Else	
			'MsgBox( "INFO: Xibo token resolved: " & """" & xibo_token & """" ) 
		End If
	End if
End Function

I assume the ‘XiboEndpoint’ clientId and secret are set there somewhere?

and that you do call access_token before trying to upload the media?

I’m not certain if you want to use ‘application/x-www-form-urlencoded’ instead of form-data there in headers.

Could you do a quick test with postman to make sure that the issue is with the script you’re using and not somewhere else?

You can also enable CMS debugging and look at the Logs page with ‘API’ in Channel to filter the logs and see what does it say there.

Yes XiboEndpoint, clientid, and secret are available.
This is an extract from a working vbs script which in inserting all data into Xibo by using the API.
Only thing that is not working is uploading images by using API.
The option application/x-www-form-urlencoded is also not working.
By using Postman it’s working fine.
Debug log is not helping me, it’s giving an error: Loading 2. All Objects = 0

Response on the API call is:
200: {“files”:[{“name”:“1510163282-9208”,“size”:716506,“type”:“multipart/form-data; boundary=------------------B0und4Ry—”,“error”:“Filetype not allowed”}]}

Hi ,
did you find a solution for this problem ?
Thanks
Thomas