Forum Post: RE: Rest API Call setBinaryField() for sending attachment to Rollbase

  • Thread starter Thread starter Godfrey Sorita
  • Start date Start date
Status
Not open for further replies.
G

Godfrey Sorita

Guest
setDataField seems to work on small files. When I encoded a 1kb PNG file to BASE64 and used it on value parameter, the REST request worked. Though when I used an 11kb PNG file, it did not work nor returned any error. Below is a sample code written in Ruby: require 'httparty' class RestGet include HTTParty base_uri 'http://localhost:8830/rest/api' def initialize () end def login(username, password, output) options = { query: {loginName: username, password: password, output: output} } self.class.get("/login", options) end def getBinaryData(sessionId, objName, id, fieldName) options = { query: {sessionId: sessionId, objName: objName, id: id, fieldName: fieldName} } self.class.get("/getBinaryData", options) end def setDataField(sessionId, objName, id, fieldName, value, contentType, fileName, output) options = { query: {sessionId: sessionId, objName: objName, id: id, fieldName: fieldName, value: value, contentType: contentType, fileName: fileName, output: output} } self.class.post("/setDataField", options) end end RestInstance = RestGet.new() RestLogin = RestInstance.login("customer1", "yourpassword", "json") #Generate sessionId for REST transaction sessionId = RestLogin["sessionId"] puts "sessionId:" + sessionId RestgetBinaryData = RestInstance.getBinaryData(sessionId, "student", 14304, "file") #Get Binary Data of "file" from Record 14304 #puts "\n ==Binary data start== \n" + RestgetBinaryData + "\n ==Binary data end== \n" b64BinaryData = Base64::encode64(RestgetBinaryData) # Encode binary data to Base64 #puts "\n ==Base 64 encoded data start== \n" + b64BinaryData + "\n ==Base 64 encoded data end== \n" RestSetDataField = RestInstance.setDataField(sessionId, "student", 14305, "file", b64BinaryData, "image/png", "ua.png", "json") #Set File Upload field "file" of Record 14305 puts RestSetDataField Can you also test uploading a small file using your script? Thanks, Godfrey

Continue reading...
 
Status
Not open for further replies.
Back
Top