1
0
-1

I am trying to use the groovy service to get the contents of attachments and pass it via ajax to our microservice. So far I have managed to grab the attachments and get the name, byte data of the attachments, however, what I would like is to get the content as string: something like

file_get_contents()

function does in PHP.

Could anyone suggest the best way to get the content of the attachments?

 

My Groovy script looks like:

 

def attachmentFile

for ( attachment in submission.getAttachments()){
	def singleFileUpload = (com.avoka.fc.core.entity.FileUpload) 		attachment.getFileUpload()
	def submissionDataDao = new SubmissionDataDao() 
	byte[] FileBytes = submissionDataDao.getAttachment(singleFileUpload) 

	attachmentFile = FileBytes.toString()

	PostAttachmentsToEburyLabs(accId, formId, attachmentFile)
}

def PostAttachmentsToEburyLabs( accId, formId){ 

	when:

		//build up the post request to the API
		def result = new 		PostRequest("http://au10tix.ebury.rocks/au10tix/document-collection-groovy.php?accId="+ accId+"&formId=" + formId)
		.setContentType('multipart/form-data')
		.setMessage(attachments)
		.execute()
		//check HttpResponse status code 
		if (result.status != 200) { 
			throw new RuntimeException(result.statusLine) 
		} 
	then: 

		logger.info result
}
  1. Margaret Antaki

    Hi Abu, Is this question related to your 'How to pass attachments to a micro service?' question? What's the status of this one? And if you have additional information or a solution please share.

CommentAdd your comment...