1
votes

I have recorded my script to upload json file through Jmeter, but now I am facing the problem while uploading json file through jmeter which is on my local drive.

I am already done with following steps:

  1. Either use full path to file, you're uploading, or copy it to JMeter's "bin" folder
  2. Don't forget to tick Use multipart/form-data for HTTP POST box
  3. Make sure you provide correct Parameter name and MIME Type

Getting exception in my response data:

{"Exception":"Object reference not set to an instance of an object."}
2

2 Answers

0
votes

For me works like this. JSON example May be Your server prefer some specific headers? E.g. content type and so on

Why you're using json file? If you facing problems with generating random JSON data, here is a JSR223 preprocessor:

import org.apache.commons.io.FileUtils;

def time = vars.get("stratup_time")
File myFile = File.createTempFile("upload-", "" );
// Generate Random length string and write to file

FileUtils.write(myFile, "{\"test\":\"$time\"", "UTF-8" )
// Store file name in variable.
vars.put( "filename", myFile.getCanonicalPath() )

And PostProcessor:

import org.apache.commons.io.FileUtils;
// Delete file and do not throw error
FileUtils.deleteQuietly(new File( vars.get("filename")));
0
votes

In order to be able to record the file upload event you need to copy your .json file to JMeter's "bin" folder, this way HTTP(S) Test Script Recorder will be able to capture the request and generate necessary HTTP Request sampler. It will also populate the HTTP Header Manager

More information: Recording File Uploads with JMeter