cancel
Showing results for 
Search instead for 
Did you mean: 

Check File Upload REST API in SOAP UI

Highlighted
Occasional Visitor

Check File Upload REST API in SOAP UI

How to check file upload in SOAP UI free. I have tried with attachment tab but File is not accepting from Attachment. 

 

I have checked the inline file upload. But its not showing in SOAP UI properties tab. 

 

Can you help to solve this problem? 

 

Thanks

Pratik  

1 REPLY 1
Highlighted
Contributor

Are you using the attachment tab in your POST request?

 

For a project I have I added a groovy step to encode an attachment to use in the body of my POST request

 

// Set results file path
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectDir = groovyUtils.projectPath
folder = projectDir+"\\Results\\";
resultFile = context.testCase.getPropertyValue("TestResultsFile")	
if (resultFile != '') {
	resultFilePath = folder + resultFile
	testRunner.testCase.setPropertyValue("resultFilePath", resultFilePath )
	
	// encode file
	ResultsPath = context.testCase.getPropertyValue("resultFilePath")
	
	def inputFile = new File(ResultsPath)
	String encoded = inputFile.bytes.encodeBase64().toString()
	testRunner.testCase.setPropertyValue("EncodedFileRequest", "$encoded" )
	
	// get request
	def request = testRunner.testCase.getTestStepByName( "AttachmentContentRequest" ).testRequest
	log.info request
	// clear existing attachments
	for( a in request.attachments ) {
	 request.removeAttachment( a )
	}
	
	// get file to attach
	//ResultsPath = context.testCase.getPropertyValue("resultFilePath")
	def file = new File(ResultsPath)
	log.info file
	if ( file == null) {
	 log.info "bad filename"
	}
	else 
	{
	 // attach and set properties
	 def attachment = request.attachFile( file, true )
	 //attachment.contentType = "application/octet-stream"
	 attachment.contentType = "base64Binary"
	 attachment.setPart( "Message" )
	}

}else{
	testRunner.gotoStepByName("Loop")
}

Then pass the values that are need in the attachment tab. The image of from SoapUI Pro but it also works with the non pro

 

image.png

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors