Importing image assets depends on the original author still hosting them in the original Contentful space
Expected Behavior
Image assets should be able to upload from locally saved files, even if the Contentful spaces from which they were originally downloaded no longer exist.
Actual Behavior
Requirement to have a url property gets in the way of using images that are stored locally but are no longer hosted on the internet.
Context
This is preventing me from creating a Contentful-based tutorial from a data model & set of content that I really liked.
I have no intention of being responsible for maintaining a Contentful space on the internet forever and ever for the rest of my life, just so contentful space import can work when readers try my tutorial.
Environment
Node Version: 15.11.0
Npm Version: output of npm -v
Operating System: Windows 10 64-bit
Package Version: 1.6.41 (contentful-cli)
Steps to reproduce
Install the Contentful CLI on your machine.
Set your command line to be in the context of your project, e.g. c:\exampleproject\
Create a file c:\exampleproject\importme.json:
{
"assets": [
{
"metadata": {
"tags": [
]
},
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "abcxyz"
}
},
"id": "OldImageAssetId",
"type": "Asset",
"environment": {
"sys": {
"id": "master",
"type": "Link",
"linkType": "Environment"
}
},
"publishedVersion": 1,
"publishedAt": "2021-01-01T00:00:00.000Z",
"firstPublishedAt": "2021-01-01T00:00:00.000Z",
"publishedCounter": 1,
"version": 1
},
"fields": {
"title": {
"en-US": "Pug dog illustration"
},
"description": {
"en-US": "An illustration of a dog made out of circles"
},
"file": {
"en-US": {
"url": "//images.ctfassets.net/abcxyz/OldImageAssetId/OldUrlSubPathId/dog.svg",
"details": {
"size": 37837,
"image": {
"width": 551,
"height": 253
}
},
"fileName": "dog.svg",
"contentType": "image/svg+xml"
}
}
}
}
]
}
(Change the size & width/height details to match your actual SVG file)
Also save dog.svg at c:\exampleproject\OldImageAssetId\OldUrlSubPathId\dog.svg
You've now set up a little test environment that replicates what would happen if you'd exported all of your image assets, including file downloads, from a Contentful space abcxyz that someone has since deleted from Contentful altogether.
Execute the command:
contentful space import --space-id YourNewSpaceId --content-file importme.json
It hangs forever at Processing Asset Pug dog illustration (OldImageAssetId)
┌──────────────────────────────────────────────────┐
│ The following entities are going to be imported: │
├─────────────────────────────────┬────────────────┤
│ Assets │ 1 │
├─────────────────────────────────┼────────────────┤
│ Content Types │ 0 │
├─────────────────────────────────┼────────────────┤
│ Tags │ 0 │
├─────────────────────────────────┼────────────────┤
│ Entries │ 0 │
├─────────────────────────────────┼────────────────┤
│ Locales │ 0 │
├─────────────────────────────────┼────────────────┤
│ Webhooks │ 0 │
├─────────────────────────────────┼────────────────┤
│ Editor Interfaces │ 0 │
└─────────────────────────────────┴────────────────┘
√ Validating content-file
√ Initialize client (1s)
√ Checking if destination space already has any content and retrieving it (1s)
√ Apply transformations to source data (1s)
> Push content to destination space
√ Connecting to space (1s)
√ Importing Locales (0s)
√ Importing Content Types (1s)
√ Publishing Content Types (1s)
√ Importing Tags (0s)
↓ Importing Editor Interfaces [skipped]
↓ Uploading Assets [skipped]
- Importing Assets
→ √ Processing Asset Pug dog illustration (OldImageAssetId)
Publishing Assets
Archiving Assets
Importing Content Entries
Publishing Content Entries
Archiving Entries
Creating Web Hooks
This problem does NOT happen if the value specified in url, //images.ctfassets.net/abcxyz/OldImageAssetId/OldUrlSubPathId/dog.svg, still actually exists on the internet. Sadly, you can't fail to pass in url at all.
Failed attempts to solve
Interestingly, this code makes some sort of image import (dropping "details" and using a random URL that is on the internet):
"file": {
"en-US": {
"url": "//www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png",
"fileName": "dog.svg",
"contentType": "image/svg+xml"
}
}
But, obviously, I don't want the Google logo as my pug dog. I want the pug dog svg file that's saved to my computer from an export of a now-gone Contentful space.
I feel like this might be something that should be simple to implement. I just ran into the issue of uploading using the JS Management API and there is support for uploading a file locally. If you search for createFromFiles on this page of the docs, you can find the structure for creating from file. Maybe try replacing the url param with the file param. The file param just takes in the file contents that you want to upload, so you will have write a script or something to read the file (as a string, Buffer, or Stream) and then pass it along.
This ticket has been closed due to inactivity. If you still need help resolving your issue, please reach out through our community Slack, or contact Contentful support directly.