# Issues with Handling multipart/form-data in Ignition SCADA SDK Rest API development

**URL:** <https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909>\
**Category:** Module Development\
**Tags:** ignition81\
**Created:** [January 15, 2025, 9:45am UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909 "2025-01-15T09:45:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Md\_Sabbir\_Ahamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md_sabbir_ahamed/32/54273_2.png) [@Md\_Sabbir\_Ahamed](https://forum.inductiveautomation.com/u/Md_Sabbir_Ahamed)\
**Post date:** [January 15, 2025, 9:45am UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/1 "2025-01-15T09:45:14Z")

</div>

Hello Ignition Community,

I am currently developing a REST API using the Ignition SCADA SDK and have encountered significant challenges when working with `multipart/form-data` requests. While all other API endpoints in my project are functioning as expected, handling file uploads has proven to be a roadblock.

Here’s what I’ve observed:

1. **File Size Inconsistencies:**

- Uploading smaller files (e.g., less than 3 KB) is unreliable. It works sometimes but fails at other times with the error:  
**You cannot pipe to this stream after the outbound request has started.**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/6/f62ef09512067ad8f5ee5795bd01b7aa1c1ba560.png)

The files could be less than 50 MB.

### **What I’ve Tried:**

1. **Multipart Configuration:** I configured the `MultipartConfigElement` in my code as follows:

```python
MultipartConfigElement multipartConfig = new MultipartConfigElement(
        BASE_DIRECTORY + File.separator + "temp", // Temp directory
        500 * 1024 * 1024L, // Max file size: 500 MB(for test)
        500 * 1024 * 1024L, // Max request size: 500 MB(for test)
        1 * 1024 * 1024 // File size threshold: 1 MB(for test)
);
req.getRequest().setAttribute("org.eclipse.jetty.multipartConfig", multipartConfig);

```

and

```python
MultipartConfigElement multipartConfig = new MultipartConfigElement(
                    BASE_DIRECTORY, // Temp dir
                    -1L, // No max file size limit for testing
                    -1L, // No max request size limit for testing
                    0 // No file size threshold
            );
            req.getRequest().setAttribute("org.eclipse.jetty.multipartConfig", multipartConfig);

```

**Gateway Configuration:** I updated the `.config` file to increase Jetty limits:

```python
wrapper.java.additional.23 = -Dorg.eclipse.jetty.server.Request.maxFormContentSize=104857600
wrapper.java.additional.24=-Dorg.eclipse.jetty.server.Request.maxFormKeys=20000
wrapper.java.additional.25=-Dorg.eclipse.jetty.server.MultiPartFormInputStream.maxParts=10000
wrapper.java.additional.26=-Dorg.eclipse.jetty.server.HttpConfiguration.requestHeaderSize=32768
wrapper.java.additional.27=-Dorg.eclipse.jetty.server.HttpConfiguration.outputBufferSize=32768
wrapper.java.additional.28=-Dorg.eclipse.jetty.server.HttpConfiguration.idleTimeout=300000

```

Code flow:  
From mountRoutes method:

```python
routes.newRoute("/upload")
                .type("multipart/form-data")
                .handler(MinimalFileUploadTest::testUpload)
                .method(HttpMethod.POST)
                .mount();

```

```python
public class MinimalFileUploadTest {

    private static final LoggerEx log = LoggerEx.newBuilder().build("streamchat.gateway.FileController");
    private static final String BASE_DIRECTORY = "C:\\uploads\\temp"; // Ensure this exists and is writable

    public static JsonObject testUpload(RequestContext req, HttpServletResponse res) {
        JsonObject responseJson = new JsonObject();
        try {
            MultipartConfigElement multipartConfig = new MultipartConfigElement(
                    BASE_DIRECTORY, // Temp dir
                    -1L, // No max file size limit for testing
                    -1L, // No max request size limit for testing
                    0 // No file size threshold
            );
            req.getRequest().setAttribute("org.eclipse.jetty.multipartConfig", multipartConfig);

            log.info("Before getParts()");
            Collection<Part> parts = req.getRequest().getParts();
            log.info("After getParts(), Parts Count: " + parts.size());

            for (Part part : parts) {
                log.info("Part Name: " + part.getName());
                log.info("Submitted Filename: " + part.getSubmittedFileName());
                log.info("Content Type: " + part.getContentType());
                log.info("Size: " + part.getSize());
            }

            responseJson.addProperty("success", true);
        } catch (Exception e) {
            log.error("Error: ", e);
            responseJson.addProperty("success", false);
            responseJson.addProperty("message", e.getMessage());
        }
        return responseJson;
    }
}

```

### **Key Challenges:**

1. Handling `multipart/form-data` in Ignition SDK appears more complex than expected. I am unsure if additional configuration is needed or if this is a limitation of the Jetty server.
2. The inconsistent behavior with small files is puzzling, as I would expect smaller uploads to work reliably.
3. **`req.getRequest().getParts()` Stuck:** The main issue seems to originate from this line in the code, where retrieving file parts is unreliable or fails altogether.

### **Questions:**

1. Has anyone successfully implemented file uploads with `multipart/form-data` using the Ignition SDK? If so, could you share guidance or examples?
2. Are there known limitations with Jetty in the Ignition Gateway that could affect multipart handling?
3. What additional configurations or best practices should I consider to ensure reliable uploads for both small and large files?

I’m eager to hear your thoughts and suggestions. Any help or insights would be greatly appreciated!

Thank you in advance! 😊

---

<div class="post-metadata">

**Author:** ![Saqib\_Shafin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/saqib_shafin/32/67615_2.png) [@Saqib\_Shafin](https://forum.inductiveautomation.com/u/Saqib_Shafin)\
**Post date:** [January 17, 2025, 5:03pm UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/2 "2025-01-17T17:03:20Z")

</div>

Not sure how to solve it exactly.

@paul-griffith, could you kindly lend us your time? What is being done wrongly here?

---

<div class="post-metadata">

**Author:** ![Bradley\_Ferreira](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@Bradley\_Ferreira](https://forum.inductiveautomation.com/u/Bradley_Ferreira)\
**Post date:** [January 21, 2025, 8:11pm UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/3 "2025-01-21T20:11:04Z")

</div>

I've had similar issues with multipart/form-data handling in the Ignition SDK- including the same "cannot pipe to this stream" response error. Haven't found a solution, unfortunately.

---

<div class="post-metadata">

**Author:** ![Md\_Sabbir\_Ahamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md_sabbir_ahamed/32/54273_2.png) [@Md\_Sabbir\_Ahamed](https://forum.inductiveautomation.com/u/Md_Sabbir_Ahamed)\
**Post date:** [January 23, 2025, 4:47am UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/4 "2025-01-23T04:47:03Z")

</div>

@pturmel do you have any idea about the issue?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 23, 2025, 12:50pm UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/5 "2025-01-23T12:50:19Z")

</div>

None at all. (No need to ping me. I read everything on this forum.)

---

<div class="post-metadata">

**Author:** ![Md\_Sabbir\_Ahamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md_sabbir_ahamed/32/54273_2.png) [@Md\_Sabbir\_Ahamed](https://forum.inductiveautomation.com/u/Md_Sabbir_Ahamed)\
**Post date:** [January 25, 2025, 12:50pm UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/6 "2025-01-25T12:50:56Z")

</div>

Thanks. 🙂

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 27, 2025, 4:18pm UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/7 "2025-01-27T16:18:22Z")

</div>

I don't really have anything to offer - maybe it's a Jetty bug? We're significantly upgrading Jetty in 8.3 🤷

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [January 27, 2025, 5:07pm UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/9 "2025-01-27T17:07:14Z")

</div>

> [@paul-griffith](#):
>
> We're significantly upgrading Jetty in 8.3

Assuming that means Jetty 12.0?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 27, 2025, 5:15pm UTC](https://forum.inductiveautomation.com/t/issues-with-handling-multipart-form-data-in-ignition-scada-sdk-rest-api-development/100909/10 "2025-01-27T17:15:10Z")

</div>

`jetty = "12.0.15"` at this moment.
