Class Upload


  • public class Upload
    extends APIRequestHandler
    /api/elicit/upload : Handler for adding an elicited transcript file with associated media/document files.
    POST
    This is the only supported method.
    • Request Body - A multi-part encoded request with the following parameters:
      transcript_type
      The transcript type for the new transcript.
      corpus
      The corpus to add the transcript to.
      episode
      The elicitation episode the transcript belongs to.
      transcript
      Transcript file to upload, which must be a plain-text file with a file name ending in .txt. (transcript is nominally the parameter to use, but any .txt file parameter will be taken to be the transcript, regardless of the name of the parameter.)
      media
      Recording associated with the transcript, if any. If specified, this must be an audio/wav file with a file name ending in .wav. (media is nominally the parameter to use, but any .wav file parameter will be taken to be the media file, regardless of the name of the parameter.)
      doc
      Document associated with the transcript, if any. If specified, this must be an application/pdf file with a file name ending in .pdf. (doc is nominally the parameter to use, but any .pdf file parameter will be taken to be the document file, regardless of the name of the parameter.)
    • Response Body - a JSON-encoded reponse of the following structure:
      {
          "title":"Elicited upload",
          "version":"20260428.1901",
          "code":0,
          "errors":[],
          "messages":[],
          "model":{}
      }
      The messages and errors arrays may contain one or more messages for the client.
    • Response Status
      • 200 : The upload was nominally successful (but should be confirmed with a call the the verify endpoint.
      • 400 : The upload request was invalid, e.g. no transcript was received.
      • 415 : Files of unsupported media types were received.
    Author:
    Robert Fromont robert@fromont.net.nz
    • Constructor Detail

      • Upload

        public Upload()
        Default constructor.
    • Method Detail

      • post

        public javax.json.JsonObject post​(RequestParameters requestParameters,
                                          Consumer<Integer> httpStatus,
                                          Function<nzilbb.ag.Graph,​String> layerGenerator)
        The POST method for the servlet.
        Parameters:
        requestParameters - Request parameter map.
        httpStatus - Receives the response status code, in case of error.
        layerGenerator - A function that will start a layer generation thread for the given transcript, and return the thread ID.
        Returns:
        JSON-encoded object representing the response
      • validateWav

        public String validateWav​(File wav)
                           throws IOException,
                                  FileNotFoundException
        Checks the given file actually appears to be a WAV file.
        Parameters:
        wav - The file to validate.
        Returns:
        An error if validation fails, null if the WAV file appears to be ok.
        Throws:
        IOException - If the file could not be read.
        FileNotFoundException - If the file doesn't exist.