Forum Discussion

RealNetworks's avatar
Occasional Contributor
11 years ago

Attaching part of the file


If someone could help me or has some kind of advice I would very appreciate it.

I need to create test request for REST service that uploads a file. File size can be large and in that case file is split into few chunks and upload REST service needs to be called few consecutive times. After splitting file, file chunks are represented as an byte arrays. Is there a way to attach byte array into REST test request? I know that it is possible to attach file with "attachFile()" method that takes file an an argument. So currently my Groovy script looks like this:

 def outputFile = null
def request = testRunner.testCase.getTestStepByName("Upload test request").testRequest
def tmpOutputFile = new File(outputFilePath).withOutputStream {
it.write bytes // bytes is an byte array that contains file chunk
outputFile = new File (outputFilePath);
def attachment = request.attachFile(outputFile, true)

Is there a simpler way of doing this that does not include creation of the temporary file out of the byte array?

Thank you in advance for your answers.

3 Replies

  • nmrao's avatar
    Champion Level 3
    Just trying to understand the problem you are facing. I see some code snippet in your first post, were you able to achieve what you intended for? or just looking for some better way?
  • RealNetworks's avatar
    Occasional Contributor
    I'm looking for a better way because creating temporary file chunks and storing them on the disk looks like a big overkill to me. Especially for the bigger files (e.g. > 50MB).