Forum Discussion

Pratik454's avatar
Occasional Visitor
7 years ago

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? 




1 Reply

  • 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
    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 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) file
    	if ( file == null) { "bad filename"
    	 // attach and set properties
    	 def attachment = request.attachFile( file, true )
    	 //attachment.contentType = "application/octet-stream"
    	 attachment.contentType = "base64Binary"
    	 attachment.setPart( "Message" )

    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