Problems
Multi-file Submissions

In a basic scenario, a submission contains a source code that is a single file. Multi-file mode allows for creating submissions consisting of multiple files.

Thanks to this, it is possible to:

  • launch complex projects consisting of multiple files,
  • use external libraries,
  • attach files that are not source code,
  • attach configuration files.

Sending all files as an archive (.tar.gz)

Use this method when you want to send a complex project containing a large number of files (e.g., when attaching an external library).

The archive is sent using the source parameter of the POST /submissions method. The following examples present how to send multi-file submission using either the curl command or PHP Client library. There are separate examples for the Compilers and the Problems modules of Sphere Engine:

$client = new ProblemsClientV4('<access_token>', '<endpoint>');

$tarSource = '<tar_source>';
try {
    $problemId = 42;
    $compilerId = 116;
    $response = $client->createSubmissionWithTarSource($problemId, $tarSource, $compilerId);
    // response['id'] stores the ID of the created submission
} catch (SphereEngineResponseException $e) {
    // catch errors
}
See a complete example of how to use PHP Client library in a multi-file mode on GitHub: Sphere Engine Problems example.
curl -X POST \
    -F "problemId=42" \
    -F "compilerId=116" \
    -F "source=@prog.py.tar.gz" \
    "https://<endpoint>/api/v4/submissions?access_token=<access_token>"

Sending all files separately

Use this method for a small number of files.

Individual files are uploaded using the files parameter of the POST /submissions method (the source parameter is ignored in this case). Execute the files parameter multiple times, separately for each file.

An example of using the curl command on Linux:

$client = new ProblemsClientV4('<access_token>', '<endpoint>');

$files = array(
   'prog.c' => '<source_code>',
   'prog.h' => '<source_code>'
);
try {
    $problemId = 42;
    $compilerId = 11;
    $response = $client->createSubmissionMultiFiles($problemId, $files, $compilerId);
    // response['id'] stores the ID of the created submission
} catch (SphereEngineResponseException $e) {
    // catch errors
}
See a complete example of how to use PHP Client library in a multi-file mode on GitHub: Sphere Engine Problems example.
curl -X POST \
    -F "problemId=42" \
    -F "compilerId=11" \
    -F "files[prog.c]=@prog.c" \
    -F "files[prog.h]=@prog.h" \
    "https://<endpoint>/api/v4/submissions?access_token=<access_token>"

Submission containing binary data

A submission can be sent in the form of binary data (e.g., when uploading an archive) or contain binary data (e.g., graphic files). Therefore, when using the multi-file mode you must create requests in the MULTIPART format (i.e. Content-Type: multipart/form-data)

It is impossible to use the JSON format and we advise against using the FORM format. In this case, the binary data is converted to a text format which can result in transferring big files and creating unnecessary overhead.

Note: The MULTIPART format allows you to transfer files in their explicit form, i.e., without converting them to a text format. The examples presented above (curl commands) use this approach.

The structure of a multi-file submission

The structure of files and directories of submissions sent in the multi-file mode is not limited in any way. However, some programming languages ​​require sending an entry file with the appropriate name and extension (depending on the programming language).

The entry file will be used to execute the submission. It must be located at the highest level of the submission's directory structure. For example, a submission in Python must contain a file named prog.pyand this file will be executed.

Supported programming languages

The following table shows a list of programming languages supported by the multi-file mode. In addition, we define the entry file, which should be located at the highest level of the submission's directory structure:

ID Name Entry file
1 C++ (gcc) a file with a "cpp" extension containing a function named "main"
2 Pascal (gpc) prog.pas
3 Perl prog.pl
4 Python 2 prog.py
10 Java a file with a "java" extension containing a class that has a method named "main"
11 C (gcc) a file with a "c" extension containing a function named "main"
15 Prolog prog
17 Ruby prog.rb
19 Pike prog
21 Haskell prog.hs
22 Pascal (fpc) prog.pas
26 Lua prog.lua
27 C# a file with a "cs" extension containing a class that has a method named "main"
28 Bash prog.sh
29 PHP prog.php
35 JavaScript (rhino) prog.js
39 Scala a file with a "scala" extension containing a global scope class named "Main"
43 Objective-C prog.m
48 Dart prog.dart
50 VB.net a file with a "vb" extension containing a module that has a function named "Main"
54 Perl 6 prog.pl
55 Java - legacy a file with a "java" extension containing a class that has a method named "main"
56 Node.js prog.js
99 Python (PyPy) prog.py
104 AWK (gawk) prog.awk
114 Go a file with a "go" extension containing the function named "main" in the main package
116 Python 3 prog.py
117 R prog.r
126 Python 3 nbc prog.py