plugins icon indicating copy to clipboard operation
plugins copied to clipboard

feat(gatsby-source-s3): download non-image files

Open NelisDrost opened this issue 3 years ago • 4 comments

I'd like to be able to retrieve files other than images from S3, and access them through GraphQL.

Currently, localfile nodes are only generated in GraphQL for image files, and not e.g.: mdx, json or other data/text files.

I'm specifically interested in mdx files (which I assume could then be ingested by gatsby-transformer-mdx).

Is there a design reason for only creating local file nodes for images? If there are drawbacks to handling all files, a config option for other file extensions to accept seems like a clean solution, e.g.: { resolve: 'gatsby-source-s3', options: { aws: { ... }, buckets: [...], file_extensions: ['.mdx', '.json'], },

NelisDrost avatar Jun 14 '22 02:06 NelisDrost

@robinmetral may know the answer. If there's no particular reason I'd be happy to accept a PR.

moonmeister avatar Jun 15 '22 15:06 moonmeister

I was trying to understand why it doesn't process my markdown files. I believe gatsby-source-s3-images would be a more accurate name for this source plugin, rather than gatsby-source-s3 😅 Looking forward to that enhancement 👍👏

sebhewelt avatar Oct 24 '22 00:10 sebhewelt

@sebhewelt You interested in contributing such an enhancement?

moonmeister avatar Oct 27 '22 15:10 moonmeister

Hey folks, I'm super sorry for the extremely late reply here, I had ignored notifications on this repo for some reason 🙈

This was previously requested for .md files but never implemented. Here's the ref on the archived repo: https://github.com/gatsby-uc/gatsby-source-s3/issues/505#issuecomment-915904529

tl;dr there is no specific design reason weighing against this. The only challenge is that the plugin was built specifically to download image files for processing by sharp, not for any other purpose—so I'm not sure what exactly needs to change beyond removing this isImage check:

https://github.com/gatsby-uc/plugins/blob/60fecbc600ce57bf82887a78f4e4d9a430b35f00/packages/gatsby-source-s3/src/gatsby-node.ts#L123

For example it's possible that the schema needs to be different, depending on what you'd like to do with your files. This would probably require some fiddling/testing but can probably be done 🙂

I unfortunately don't have any time to implement this (and I haven't worked with Gatsby for some time, so would probably not be the best person to do it). But consider this a green light for a contribution 🟢

robinmetral avatar Dec 02 '22 14:12 robinmetral