fluttercurlserverpostman-mocks

How to create a Postman server mock for uploading file and doing some uploading test of Flutter code?


I'm trying to connect to a printer server to be able to save the printing files directly in the printer storage. I'm able to do it using the curl curl -v -H 'Content-Type:application/octet-stream' 'http://192.168.1.125/upload?X-Filename=model.gcode' --data-binary @model.gcode Now I'm trying to add this function to a Flutter app but don't works.... So now I am trying to debug the code using a postman server. Can you help me to create a postman server mock to upload the file as binary, like in this curl code?

curl -v -H 'Content-Type:application/octet-stream' 'http://192.168.1.125/upload?X-Filename=model.gcode' --data-binary @model.gcode

I want to create it because I want to test this Flutter code witch isn't working in the server of the printer.

FLUTTER CODE:

  Future<void> uploadFile(File file) async {
///Using HTTP Package
 Map<String, String> headers = {
  "Content-type": "application/octet-stream",
};
var stream = new http.ByteStream(DelegatingStream.typed(file.openRead()));
var length = await file.length();
var uri = Uri.parse("http://192.168.1.125/upload?X-Filename=nupo.gcode");

var request = new http.MultipartRequest("POST", uri);
var multipartFile = new http.MultipartFile('application', stream, length,
    filename: file.path);
request.headers.addAll(headers);
request.files.add(multipartFile);
var response = await request.send();
print(response.statusCode);
response.stream.transform(utf8.decoder).listen((value) {
  print(value);
});
}

The server should be able to receive binary file and the command should be upload?X-Filename=filename.gcode, X-Filename is the command to give the name.

(this files are 3D printing files so .gcode is the enstention of motor command)


Solution

  • Postman is not a server usable for this scope. You can use it only for testing an existing server. Best practice with postman or visiti [POstman support][1]