Skip to content

Can't update fields of an already uploaded media using the S3 adapter #7037

Closed

Description

@fofoy

Link to reproduction

No response

Payload Version

3.0.0-beta.56

Node Version

20.12.2

Next.js Version

15.0.0-rc.0

Describe the Bug

Whenever I want to update a field (e.g. Alt field), I get a 500 error when I try to submit the form.

Here is the log from the console
image

Reproduction Steps

Install Payload v3.0.0-beta.56 with the default Media Collection
Install @payloadcms/storage-s3 v3.0.0-beta.56
Set up S3 storage (I tried both on minIO and AWS S3 and I get the same behavior)
Upload a first Media
Update the Alt field and submit the form

Adapters and Plugins

@payloadcms/db-postgres v3.0.0-beta.56
@payloadcms/storage-s3 v3.0.0-beta.56

Activity

  1. added
    status: needs-triage
    on Jul 5, 2024
  2. removed
    status: needs-triage
    on Jul 8, 2024
  3. fofoy commented on Aug 7, 2024

    @fofoy
    ContributorAuthor

    Any news on this one ? Is there anything I can help you with @PatrikKozak ?

  4. PatrikKozak commented on Aug 7, 2024

    @PatrikKozak
    Contributor

    Hey @fofoy - we'll get right on this!

  5. PatrikKozak commented on Aug 8, 2024

    @PatrikKozak
    Contributor

    Hi @fofoy - I did some testing on my end and was not able to reproduce the above issue.

    It may have something to do with your S3 storage setup - do you have a reverse proxy setup?

    Is this purely local?

    Just want to get some additional information before I can dig deeper into this - thank you!

  6. added
    status: cant-reproduce
    on Aug 8, 2024
  7. fofoy commented on Aug 8, 2024

    @fofoy
    ContributorAuthor

    Hi @PatrikKozak I have the same issue in local (using a dockerized MinIO instance) and on my staging environment using an AWS S3 bucket so it doesn't seem to be a setup issue.

  8. PatrikKozak commented on Aug 8, 2024

    @PatrikKozak
    Contributor

    @fofoy Thanks for the info - hmm unfortunately there isn't enough here to fully understand what could be causing this issue.

    A couple things though, could you try and log out some of the info in that function where the error is coming from (in your node_modules) - this may be able to give us some more information

    Also, could you update your payload packages versions to latest (just in case) - I'd like to get to the bottom of this but just will need more info to continue

  9. fofoy commented on Aug 27, 2024

    @fofoy
    ContributorAuthor

    @PatrikKozak Thanks, I had the time to update my project to latest beta version 91 and the problem remains, I'll dig further to see where it's going wrong and I'll let you know.

  10. changed the title [-]Can't update fields of an already updoaded media using the S3 adapter[/-] [+]Can't update fields of an already uploaded media using the S3 adapter[/+] on Aug 27, 2024
  11. fofoy commented on Sep 23, 2024

    @fofoy
    ContributorAuthor

    Hi @PatrikKozak here is the result of logging the Promise getExternalFile on line 41 of generateFileData.js file:

    Promise {
      <pending>,
      [Symbol(async_id_symbol)]: 652801,
      [Symbol(trigger_async_id_symbol)]: 652790,
      [Symbol(kResourceStore)]: {
        url: {
          pathname: '/api/media/c26034b9-71ab-4e88-8ff1-2dfc5a980261',
          search: '?depth=0&fallback-locale=null'
        },
        headers: [Getter],
        cookies: [Getter],
        mutableCookies: [Getter],
        draftMode: [Getter],
        reactLoadableManifest: {},
        assetPrefix: '',
        afterContext: undefined,
        isHmrRefresh: undefined,
        serverComponentsHmrCache: undefined
      },
      [Symbol(kResourceStore)]: {
        isStaticGeneration: false,
        page: '/(payload)/api/[...slug]/route',
        fallbackRouteParams: null,
        route: '/api/[...slug]',
        incrementalCache: IncrementalCache {
          locks: Map(0) {},
          unlocks: Map(0) {},
          hasCustomCacheHandler: false,
          dev: true,
          disableForTestmode: false,
          minimalMode: false,
          requestHeaders: [Object],
          requestProtocol: 'https',
          allowedRevalidateHeaderKeys: undefined,
          prerenderManifest: [Object],
          revalidateTimings: [SharedRevalidateTimings],
          fetchCacheKeyPrefix: '',
          cacheHandler: [FileSystemCache]
        },
        isRevalidate: false,
        isPrerendering: undefined,
        fetchCache: undefined,
        isOnDemandRevalidate: undefined,
        isDraftMode: undefined,
        requestEndedState: undefined,
        revalidate: 0,
        tags: [
          '_N_T_/layout',
          '_N_T_/(payload)/layout',
          '_N_T_/(payload)/api/layout',
          '_N_T_/(payload)/api/[...slug]/layout',
          '_N_T_/(payload)/api/[...slug]/route',
          '_N_T_/api/media/c26034b9-71ab-4e88-8ff1-2dfc5a980261'
        ],
        nextFetchId: 2
      },
      [Symbol(kResourceStore)]: undefined,
      [Symbol(kResourceStore)]: undefined,
      [Symbol(kResourceStore)]: undefined,
      [Symbol(kResourceStore)]: { isAppRoute: true, isAction: false }
    }
    

    and here is the actual error when trying to fetch the file :

    TypeError: fetch failed
         at node:internal/deps/undici/undici:12618:11
         at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
         at async getExternalFile (webpack-internal:///(rsc)/../node_modules/.pnpm/[email protected][email protected][email protected][email protected]
     a48-202_bgnc5eiwwsaz2mukappcno4s3m/node_modules/payload/dist/uploads/getExternalFile.js:18:21) {
       cause: Error: connect ECONNREFUSED 127.0.0.1:443
           at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16)
           at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
         errno: -111,
         code: 'ECONNREFUSED',
         syscall: 'connect',
         address: '127.0.0.1',
         port: 443
       }
     }
      ⨯ unhandledRejection: TypeError: fetch failed
         at node:internal/deps/undici/undici:12618:11
         at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
         at async getExternalFile (webpack-internal:///(rsc)/../node_modules/.pnpm/[email protected][email protected][email protected][email protected]
     a48-202_bgnc5eiwwsaz2mukappcno4s3m/node_modules/payload/dist/uploads/getExternalFile.js:18:21) {
       cause: Error: connect ECONNREFUSED 127.0.0.1:443
           at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16)
           at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
         errno: -111,
         code: 'ECONNREFUSED',
         syscall: 'connect',
         address: '127.0.0.1',
         port: 443
       }
     }
      ⨯ unhandledRejection: TypeError: fetch failed
         at node:internal/deps/undici/undici:12618:11
         at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
         at async getExternalFile (webpack-internal:///(rsc)/../node_modules/.pnpm/[email protected][email protected][email protected][email protected]
     a48-202_bgnc5eiwwsaz2mukappcno4s3m/node_modules/payload/dist/uploads/getExternalFile.js:18:21) {
       cause: Error: connect ECONNREFUSED 127.0.0.1:443
           at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16)
           at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
         errno: -111,
         code: 'ECONNREFUSED',
         syscall: 'connect',
         address: '127.0.0.1',
         port: 443
       }
     }
    

    So it seems like it's something to do with the network. I'm running everything in Docker with several containers for the postgres db, the S3 instance (minIO) and the payload admin but it also does the same on our dev cluster (kubernetes) with an AWS S3 instance connected to it.

  12. nickejoha commented on Oct 17, 2024

    @nickejoha

    Hi @PatrikKozak and @fofoy

    I'm having the same problem as well. I can't edit any fields of an already uploaded file, and I got the same error as described above.

    We also run our environments in kubernetes and we use Google cloud storage for storing files. I have however noticed that when I'm running payload locally (and still using google cloud storage for storing files) it works. When I'm running payload in docker I get the same error we got in our kubernetes environments.

    @fofoy Have you found any temporary workaround for this problem?

  13. fofoy commented on Oct 17, 2024

    @fofoy
    ContributorAuthor

    Hi @nickejoha, I didn't have the time to dig any further than this yet as I need to make progress on my current project but that's definitely something that needs to be sorted, I'll try to invest more time in a bit.

  14. 14 remaining items

  15. firatciftci commented on Jun 18, 2025

    @firatciftci

    I'm also experiencing the same issue; I'm using the S3 Adapter with a Cloudflare R2 bucket, and everything works fine when it comes to creating, reading, and deleting operations, but update does not work. Here is my error printout when I try to update the "description" field:

    [01:56:38] ERROR: There was a problem while uploading the file. Blocked unsafe attempt to http://localhost:6002/api/media/file/SCR-20250523-jnsh.png
        err: {
          "type": "FileRetrievalError",
          "message": "There was a problem while uploading the file. Blocked unsafe attempt to http://localhost:6002/api/media/file/SCR-20250523-jnsh.png",
          "stack":
              FileRetrievalError: There was a problem while uploading the file. Blocked unsafe attempt to http://localhost:6002/api/media/file/SCR-20250523-jnsh.png
                  at generateFileData (file:///Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/uploads/generateFileData.js:53:19)
                  at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
                  at async updateByIDOperation (file:///Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/collections/operations/updateByID.js:80:61)
                  at async updateByIDHandler (file:///Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/collections/endpoints/updateByID.js:16:17)
                  at async handleEndpoints (file:///Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/utilities/handleEndpoints.js:169:26)
                  at async /Users/firatciftci/Developer/misc/artsumer/.next/server/chunks/node_modules__pnpm_94f68aa0._.js:29799:26
                  at async AppRouteRouteModule.do (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:26:34112)
                  at async AppRouteRouteModule.handle (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:26:41338)
                  at async doRender (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/base-server.js:1518:42)
                  at async DevServer.renderToResponseWithComponentsImpl (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/base-server.js:1920:28)
                  at async DevServer.renderPageComponent (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/base-server.js:2408:24)
                  at async DevServer.renderToResponseImpl (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/base-server.js:2445:32)
                  at async DevServer.pipeImpl (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/base-server.js:1008:25)
                  at async NextNodeServer.handleCatchallRenderRequest (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/next-server.js:305:17)
                  at async DevServer.handleRequestImpl (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/base-server.js:900:17)
                  at async /Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/dev/next-dev-server.js:371:20
                  at async Span.traceAsyncFn (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/trace/trace.js:157:20)
                  at async DevServer.handleRequest (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/dev/next-dev-server.js:368:24)
                  at async invokeRender (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/lib/router-server.js:237:21)
                  at async handleRequest (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/lib/router-server.js:428:24)
                  at async requestHandlerImpl (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/lib/router-server.js:452:13)
                  at async Server.requestListener (/Users/firatciftci/Developer/misc/artsumer/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_b5160444ab580599d92acf97540046d0/node_modules/next/dist/server/lib/start-server.js:158:13)
          "data": null,
          "isOperational": true,
          "isPublic": false,
          "status": 500,
          "name": "FileRetrievalError"
        }
     PATCH /api/media/1977?depth=0&fallback-locale=null 500 in 406ms
    

    Important to note that, if I turn off the upload.filesRequiredOnCreate flag, create a new Media item with no image, and then edit its "description" field, I have no issues updating it. This only occurs when there is an image attached.

    I have also checked the Content-Length and the "origin" header of the update request, and those seem to be all fine.

  16. tsemachh commented on Jun 19, 2025

    @tsemachh
    Contributor

    Happens also to me on local storage and also on GCS storage so it's not related to S3
    Look at #12622 (comment)
    Same error occurs in other places

  17. thopedam commented on Jun 19, 2025

    @thopedam

    I think this is a new error (@firatciftci and @tsemachh and also me 😀 are having) It seems to have started with version 0.43.0.
    Downgrading to 0.42.0 fixes it for me. I also tested 0.39.0-0.42.0 no issues there as well.

    EDIT: a new issue has been added: #12876

  18. removed
    status: needs-triage
    on Jun 24, 2025
  19. kendelljoseph commented on Jun 25, 2025

    @kendelljoseph
    Contributor

    @firatciftci #12927 should fix the problem.

  20. removed their assignment
    on Jun 26, 2025
  21. greenlover1991 commented on Aug 13, 2025

    @greenlover1991

    Just want to share based on our setup in above comment after upgrading to v3.46.0:

    Production setup:

    1. Behind nginx
    2. Self-host on Openshift cluster
    3. Payloadcms container is served on port 3000

    The pasteURL that didn't worked:

    allowList: [
        {
          hostname: "my-internal-openshift-pod-svc-name.my-namespace", # Openshift service name
          port: "80", # node port
          protocol: 'http',
        },
      ]

    The pasteURL that finally worked:

    allowList: [
        {
          hostname: "localhost",
          port: "3000",
          protocol: 'http',
        },
      ]

    Openshift service name as hostname will not work because safeFetch() will attempt to do a DNS lookup and disallow private IP address. Which I think is a bug on Payloadcms side cc @kendelljoseph @DanRibbens

    https://github.com/payloadcms/payload/blob/v3.46.0/packages/payload/src/uploads/safeFetch.ts#L20

    const isSafeIp = (ip: string) => {
      try {
        ...
        if (range !== 'unicast') {
          return false // Private IP Range
        }
       ...
    }

    Related to #13146

  22. JessRynkar commented on Jan 19, 2026

    @JessRynkar
    Member

    This issue hasn’t had activity in a while and relates to several releases ago, so we’re going to close it for now. If it’s still occurring on the latest version, please open a new issue with updated reproduction steps and environment details so we can investigate.

  23. removed
    status: cant-reproduce
    on Jan 19, 2026
  24. github-actions commented on Jan 27, 2026

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  25. locked as resolved and limited conversation to collaborators on Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions