Skip to content

createRemoteFileNode failing on contentLength check, but file might be not incomplete at all #28983

Description

@laurenskling

Description

I am using the createRemoteFileNode as explained in https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/#feeding-remote-images-into-gatsby-image, it takes in my image field, which can be a png, jpg, [...] or svg, sourcing from Cloudinary.

Now with the latest gatsby releases my code starts crashing to Failed to download ... after 3 attempts (the INCOMPLETE_RETRY_LIMIT one) and I seem to have narrowed it down to svgs. And even more so: https://github.com/gatsbyjs/gatsby/pull/28547/files#diff-ed27ffe776b2ef7b45a29f65fc4b9b01922de1c85ec42e9a92722b3949110a82R188 failing to match content lengths makes the code crash the download. Now I debugged Cloudinary shipping my svgs gzipped. I'm no expert on content length, but my (not so) wild guess right now is that zipped svg's are indeed not the same content length as written bytes?

Steps to reproduce

adding a createRemoteFileNode to a remote url. my code (fetching remote images on Strapi uploads via gatsby-source-graphql):

createResolvers({
    STRAPI_UploadFile: {
      imageFile: {
        type: 'File',
        resolve: async (source) => {
          if (!source.url) {
            return null;
          }
          let res;
          try {
            res = await createRemoteFileNode({
              url: source.url,
              store,
              cache,
              createNode,
              createNodeId,
              reporter,
            });
          } catch (err) {
            console.error(`[createResolvers] error in fetching remote image ${source.url} (${source.name}):`, err);
            throw err;
          }
          return res;
        },
      },

Expected result

A file can be checked on incompleteness, including SVGs and zipped files

Actual result

An error is thrown because the file seems to have an incorrect content length. (but the file is downloaded correctly)

Environment

System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-1060NG7 CPU @ 1.20GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.15.1 - /var/folders/gh/yg99pwqj2rngz5wysjcgl8ph0000gn/T/yarn--1610380123259-0.7945398836762099/node
Yarn: 1.22.4 - /var/folders/gh/yg99pwqj2rngz5wysjcgl8ph0000gn/T/yarn--1610380123259-0.7945398836762099/yarn
npm: 6.14.8 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 87.0.4280.88
Safari: 14.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: source-pluginsRelates to the Gatsby source plugins (e.g. -filesystem)type: bugAn issue or pull request relating to a bug in Gatsby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions