{"record":{"id":"1a24c750591ec699","repo":"flowable/flowable-engine","slug":"error-getting-file-bytes","errorCode":null,"errorMessage":"Error getting file bytes","messagePattern":"Error getting file bytes","errorType":"http","errorClass":"FlowableException","httpStatus":500,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/repository/BaseModelSourceResource.java","lineNumber":29,"sourceCode":" * limitations under the License.\n */\n\npackage org.flowable.rest.service.api.repository;\n\nimport org.flowable.common.engine.api.FlowableException;\nimport org.springframework.web.multipart.MultipartFile;\n\n/**\n * @author Tijs Rademakers\n */\npublic abstract class BaseModelSourceResource extends BaseModelResource {\n\n    public byte[] getFileBytes(MultipartFile file) {\n        byte[] byteArray = null;\n        try {\n            byteArray = file.getBytes();\n        } catch (Exception e) {\n            throw new FlowableException(\"Error getting file bytes\", e);\n        }\n        return byteArray;\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":34,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/repository/BaseModelSourceResource.java#L11-L34","documentation":"getFileBytes wraps any exception thrown by MultipartFile.getBytes() (e.g. IOException while reading the uploaded file from its temporary storage) in a FlowableException with the message 'Error getting file bytes'. It is thrown from the REST layer when the raw bytes of an uploaded deployment file cannot be read. The original cause is attached as the exception cause.","triggerScenarios":"Calling a REST endpoint that accepts a MultipartFile (e.g. model/deployment upload) where file.getBytes() throws — most commonly because the underlying temporary upload file was deleted, the temp directory is unwritable/full, or the request content was already consumed.","commonSituations":"Servlet container temp directory cleaned up mid-request (aggressive tmpwatch/systemd-tmpfiles), disk full on /tmp, multipart resolver misconfiguration, or very large uploads hitting container limits so the part data is unavailable.","solutions":["Check that the servlet container's temp directory (java.io.tmpdir / multipart location) exists, is writable, and has free space","Verify multipart configuration (spring.servlet.multipart max-file-size/max-request-size, location) matches the upload size","Inspect the cause chain of the FlowableException (getCause()) for the real IOException and fix that root cause","Retry the upload; if the temp file was removed by an external cleanup job, exclude the multipart temp dir from that job"],"exampleFix":"// before: server just sees FlowableException with no cause handling\ntry {\n    byte[] data = file.getBytes();\n} catch (IOException e) {\n    log.error(\"Upload read failed\", e); // surface real cause; ensure temp dir is writable\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (file == null || file.isEmpty()) throw new IllegalArgumentException(\"Uploaded file is empty\");","typeGuard":"boolean isReadable(MultipartFile f) { return f != null && !f.isEmpty(); }","tryCatchPattern":"try {\n    byte[] bytes = file.getBytes();\n} catch (FlowableException e) {\n    logger.error(\"Failed reading uploaded file\", e.getCause());\n    return ResponseEntity.status(502).body(\"Upload read failed: check temp dir\");\n}","preventionTips":["Ensure the servlet container temp directory exists, is writable, and is excluded from tmp-cleanup jobs","Set multipart max-file-size/max-request-size to accommodate expected uploads","Call file.getBytes() once, before any other code consumes the request input stream"],"tags":["file-read","multipart-upload","io","rest"],"backgroundTag":"file-read-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}