Gathering detailed insights and metrics for @aaaz/gatsby-plugin-remote-images
Gathering detailed insights and metrics for @aaaz/gatsby-plugin-remote-images
Gathering detailed insights and metrics for @aaaz/gatsby-plugin-remote-images
Gathering detailed insights and metrics for @aaaz/gatsby-plugin-remote-images
💾 A Gatsby.js plugin for downloading and linking remote images from another node's field for the benefits of gatsby-image.
npm install @aaaz/gatsby-plugin-remote-images
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
67 Commits
2 Forks
9 Branches
1 Contributors
Updated on Dec 05, 2020
Latest Version
2.2.0
Package Id
@aaaz/gatsby-plugin-remote-images@2.2.0
Unpacked Size
21.93 kB
Size
6.04 kB
File Count
3
NPM Version
6.14.6
Node Version
12.16.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
1
Download images from any string field on another node so that those images can
be queried with gatsby-image
.
First, install the plugin.
npm install --save gatsby-plugin-remote-images
Second, set up the gatsby-config.js
with the plugin. The most common config
would be this:
1module.exports = { 2 plugins: [ 3 { 4 resolve: `gatsby-plugin-remote-images`, 5 options: { 6 nodeType: 'MyNodes', 7 imagePath: 'path.to.image', 8 }, 9 }, 10 ], 11};
Option Name | Description | Required | Default |
---|---|---|---|
nodeType | The node type that has the images you want to grab. This is generally the camelcased version of the word after the 'all' in GraphQL ie. allMyImages type is myImages | ✅ | null |
imagePath | For simple object traversal, this is the string path to the image you want to use, relative to the node. This uses lodash .get, see docs for accepted formats here. For traversing objects with arrays at given depths, see how to handle arrays along the path below. | ✅ | null |
name | Name you want to give new image field on the node. Defaults to localImage . | ❌ | localImage |
auth | Adds htaccess authentication to the download request if passed in. | ❌ | {} |
ext | Sets the file extension. Useful for APIs that separate the image file path from its extension. Or for changing the extension. Defaults to existing file extension. | ❌ | null |
prepareUrl | Allows modification of the URL per image if needed. Expects a function taking the original URL as a parameter and returning the desired URL. | ❌ | null |
type | Tell the plugin that the leaf node is an array of images instead of one single string. Only option here is array . For example usage, see here. | ❌ | object |
However, you may need more optional config, which is documented here.
1module.exports = { 2 plugins: [ 3 { 4 resolve: `gatsby-plugin-remote-images`, 5 options: { 6 nodeType: 'MyNodes', 7 imagePath: 'path.to.image', 8 // ** ALL OPTIONAL BELOW HERE: ** 9 name: 'theNewImageField', 10 auth: { htaccess_user: `USER`, htaccess_pass: `PASSWORD` }, 11 ext: '.jpg', 12 prepareUrl: url => (url.startsWith('//') ? `https:${url}` : url), 13 }, 14 }, 15 ], 16};
Why do you need this plugin? The fantastic gatsby-image tool only works on relative paths to locally stored images. This lets you use it on images from an API with an absolute path. For example, look at these two response from one GraphQL query:
Query
1allMyNodes { 2 edges { 3 node { 4 id 5 imageUrl 6 } 7 } 8 }
Absolute imageUrl NOT available to gatsby-image
1allMyNodes: [ 2 { 3 node: { 4 id: 123, 5 imageUrl: 'http://remoteimage.com/url.jpg', 6 }, 7 }, 8];
Relative imageUrl IS available to gatsby-image
1allMyNodes: [ 2 { 3 node: { 4 id: 123, 5 imageUrl: 'localImages/url.jpg', 6 }, 7 }, 8];
If you don't control the API that you are hitting (many third party APIs return a field with a string to an absolute path for an image), this means those image aren't run through gatsby-image and you lose all of the benefits.
To get the images and make them available for the above example, follow the install instructions and your config should look like this:
1module.exports = { 2 plugins: [ 3 { 4 resolve: `gatsby-plugin-remote-images`, 5 options: { 6 nodeType: 'MyNodes', 7 imagePath: 'imageUrl', 8 // OPTIONAL: Name you want to give new image field on the node. 9 // Defaults to 'localImage'. 10 name: 'allItemImages', 11 }, 12 }, 13 ], 14};
Now, if we query allMyNodes
we can query as we would any gatsby-image node:
1allMyNodes { 2 edges { 3 node { 4 localImage { 5 childImageSharp { 6 fluid(maxWidth: 400, maxHeight: 250) { 7 ...GatsbyImageSharpFluid 8 } 9 } 10 } 11 } 12 } 13}
Note: Many Gatsby source plugins already do this work for you under the hood. So if you are working with a common CMS's Gatsby plugin, odds are that you don't need this!
gatsby-source-graphql
Due to the way gatsby-source-graphql
creates nodes, it is currently impossible
for any transformer type plugin to traverse the data from that plugin.
Please read this issue for explanation.
As soon as that as fixed in gatsby-source-graphql
, this plugin will be tested
to make sure it works with it as well.
Since some GraphQL APIs will send back objects with nested arrays where your
target data lives, gatsby-plugin-remote-images
also supports traversing
objects that have arrays at arbitrary depths. To opt in to this feature, add an
array literal, []
, to the end of the node you want to indicate is an array.
Given an object structure like this:
1allMyNodes { 2 nodes: [ 3 { 4 imageUrl: 'https://...' 5 }, 6 ... 7 ] 8}
To get the images and make them available for the above example, your config should look like this:
1module.exports = { 2 plugins: [ 3 { 4 resolve: `gatsby-plugin-remote-images`, 5 options: { 6 nodeType: 'MyNodes', 7 imagePath: 'nodes[].imageUrl', 8 }, 9 }, 10 ], 11};
Now, if we query allMyNodes
we can query as we would any gatsby-image node:
1allMyNodes { 2 nodes { 3 localImage { 4 childImageSharp { 5 fluid(maxWidth: 400, maxHeight: 250) { 6 ...GatsbyImageSharpFluid 7 } 8 } 9 } 10 } 11}
Note: While lodash .get
doesn't natively support this syntax, it is still
used to traverse the object structure, so
the documentation for .get
still
applies in full.
In case your API offers an image path to an array of images, instead of just one, there is a way to handle that with the plugin. For instances where there is an array somewhere along the path to the images, see above.
For example, you API returns:
1// MyNode 2{ 3 date: '1-1-2010', 4 category: 'cats' 5 // Note that here there are multiple images at the *leaf* node where the images are found. 6 images: [ 7 'https://.../image1.png', 8 'https://.../image2.png' 9 ] 10}
To make your local image field an array of these images, adjust your config accordingly:
1 { 2 resolve: `gatsby-plugin-remote-images`, 3 options: { 4 nodeType: 'MyNodes', 5 // Making this plural (optional). 6 name: 'localImages', 7 // Path to the leaf node. 8 imagePath: 'images', 9 // Set type to array. 10 type: 'array' 11 } 12}
Now, if we query allMyNodes
we can query as we would any gatsby-image node,
but now localImage
(or localImages
as in the example above) we would get an
array of Gatsby images, instead of just one.
1allMyNodes { 2 nodes { 3 localImages { 4 childImageSharp { 5 fluid(maxWidth: 400, maxHeight: 250) { 6 ...GatsbyImageSharpFluid 7 } 8 } 9 } 10 } 11}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More