Forum Discussion
- bagochipsContributor
where are you wanting to upload a file to? I've used scripts to do similar things but they are specific to where I am loading them to.
Here is some groovy for loading a file to a service that uploads files. It calls the REST API and loads the details to the "Attachment" tab on the service request.
// 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// 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)
if ( file == null) {
log.info "bad filename"
}
else
{
// attach and set properties
def attachment = request.attachFile( file, true )
attachment.contentType = "base64Binary"
attachment.setPart( "Message" )
}
Related Content
- 2 years ago
- 4 years ago
- 2 years ago
- 7 years ago
Recent Discussions
- 15 years ago