2

I am using a generated OpenAPI Client for uploading a file (~190mb) to a service. When using the generated method, the code fails with an OutOfMemoryException.

How can I tell the OpenAPI Client to use a buffered reader/writer for the file? Is there another solution?

Log:

2022-02-22 22:37:45.569  INFO 1 --- [  XNIO-1 task-3] okhttp3.OkHttpClient                     : Content-Type: multipart/form-data; boundary=b75abfd1-9ae1-4c86-b69e-e444d341b051
2022-02-22 22:37:45.570  INFO 1 --- [  XNIO-1 task-3] okhttp3.OkHttpClient                     : Content-Length: 193464281
2022-02-22 22:37:45.570  INFO 1 --- [  XNIO-1 task-3] okhttp3.OkHttpClient                     : Authorization: Basic XXX
2022-02-22 22:37:45.570  INFO 1 --- [  XNIO-1 task-3] okhttp3.OkHttpClient                     : Accept: application/json
2022-02-22 22:37:45.571  INFO 1 --- [  XNIO-1 task-3] okhttp3.OkHttpClient                     : User-Agent: OpenAPI-Generator/0.0.13/java
2022-02-22 22:37:45.744  INFO 1 --- [  XNIO-1 task-3] okhttp3.OkHttpClient                     :
2022-02-22 22:37:49.588 ERROR 1 --- [  XNIO-1 task-3] o.z.problem.spring.common.AdviceTraits   : Internal Server Error

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: Java heap space

Code:

private ApiClient login() {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setDebugging(true);
        defaultClient.setBasePath(this.basepath);

        // Configure HTTP basic authorization: Basic
        HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic");
        Basic.setUsername(this.username);
        Basic.setPassword(this.password);

        return defaultClient;
    }

private void upload() {
        String filename = "file.file";
        ApiClient client = login();
        MediaApi mediaApi = new MediaApi();
        mediaApi.setApiClient(client);
        Media m = mediaApi.mediaCreate(new File(filename));
}

OpenApi:

  "swagger": "2.0",
  "info": {
    "title": "MediaCMS API",
    "version": "0.0.13"
  },
  "host": "localhost:8085",
  "schemes": ["http"],
  "basePath": "/api/v1",
  "consumes": ["application/json"],
  "produces": ["application/json"],
  "securityDefinitions": {
    "Basic": {
      "type": "basic"
    }
  },
  "security": [
    {
      "Basic": []
    }
  ],
  "paths": {
    "/media": {
      "post": {
        "operationId": "media_create",
        "summary": "Add new Media",
        "description": "Adds a new media, for authenticated users",
        "parameters": [
          {
            "name": "media_file",
            "in": "formData",
            "description": "media_file",
            "required": true,
            "type": "file"
          },
          {
            "name": "description",
            "in": "formData",
            "description": "description",
            "required": false,
            "type": "string"
          },
          {
            "name": "title",
            "in": "formData",
            "description": "title",
            "required": false,
            "type": "string"
          }
        ],
        "responses": {
          "201": {
            "description": "response description",
            "schema": {
              "$ref": "#/definitions/Media"
            }
          },
          "401": {
            "description": "bad request"
          }
        },
        "consumes": ["multipart/form-data", "application/x-www-form-urlencoded"],
        "tags": ["Media"]
      }
    }
  }
}
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.