# @apollo/datasource-rest and multipart file uploads

**URL:** <https://community.apollographql.com/t/apollo-datasource-rest-and-multipart-file-uploads/5942>\
**Category:** Server\
**Tags:** server\
**Created:** [March 15, 2023, 10:47am UTC](https://community.apollographql.com/t/apollo-datasource-rest-and-multipart-file-uploads/5942 "2023-03-15T10:47:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olsch01](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olsch01](https://community.apollographql.com/u/olsch01)\
**Post date:** [March 15, 2023, 10:47am UTC](https://community.apollographql.com/t/apollo-datasource-rest-and-multipart-file-uploads/5942/1 "2023-03-15T10:47:52Z")

</div>

Hi,

we currently use `apollo-datasource-rest`, with which it’s possible to pass a `body` that is `FormData` as a second argument to the `post` method of a data source. That’s what we did for file uploads. But with `@apollo/datasource-rest` that’s not possible anymore.  
Looking at the source code of the `fetch` method of both packages, it seems like now everything that is not passing the following conditions (which are present in both) is being ignored:

```auto
    if (
      request.body !== undefined &&
      request.body !== null &&
      (request.body.constructor === Object ||
        Array.isArray(request.body) ||
        ((request.body as any).toJSON &&
          typeof (request.body as any).toJSON === 'function'))
    )

```

With `apollo-datasource-rest` a body which fell through that if statement was simply passed on as is. Does someone know what the reasoning behind this is? Maybe in the past we accidentally leveraged a “loophole” in the implementation?

---

<div class="post-metadata">

**Author:** ![olsch01](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olsch01](https://community.apollographql.com/u/olsch01)\
**Post date:** [March 18, 2023, 12:35pm UTC](https://community.apollographql.com/t/apollo-datasource-rest-and-multipart-file-uploads/5942/2 "2023-03-18T12:35:51Z")

</div>

See [Posting FormData as body (for file uploads) not possible anymore · Issue #174 · apollographql/datasource-rest · GitHub](https://github.com/apollographql/datasource-rest/issues/174)

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:49pm UTC](https://community.apollographql.com/t/apollo-datasource-rest-and-multipart-file-uploads/5942/3 "2025-02-06T20:49:12Z")

</div>


