Issue with image assets not showing up in Sanity Studio CMS or front end after bulk downloading and optimizing dataset.

2 replies
Last updated: Nov 26, 2021
Hi, I am try to bulk download .tar.gz of dataset in sanity and optimized the images manually (the images folder) without renaming any files. Then I repacked the folder as .tar.gz (same folder structure with asset.json and data.jsonld and images folder). I have been trying for a while now, but the issue is that when I import to new dataset the image assets aren't showing up in sanity studio cms or the front end. But i do see the images in the media gallery plugin inside sanity, as well as via graphql on the main dataset
Nov 25, 2021, 4:04 PM
Hi, could someone help please. I am trying to launch today
Nov 26, 2021, 5:25 AM
const fs = require('fs')

const util = require('util')

const ndjson = require('ndjson')



function rebuildFileAssetUrls(val, key) {

if(typeof val === 'string') {
`const newVal = val.replace('file://./',
file://${__dirname}/
)`

return newVal

}

else if(Array.isArray(val)) {

return val.map((item)=> rebuildFileAssetUrls(item))


}

else if(typeof val === 'object' && val != null) {

const entries = Object.entries(val)

let newItem = {}

entries.forEach(([key, val])=> newItem[key] = rebuildFileAssetUrls(val, key))


return newItem

}

else if(typeof val === 'undefined' || val == null) {

return val

}

else if(typeof val === 'boolean' || typeof val === 'number') {

return val

}

else {

return val

}

}


(async ()=> {

let data = await new Promise((resolve)=> {

let temp = []

fs.createReadStream('./data.ndjson')

.pipe(ndjson.parse())

.on('data', function(obj) {

temp.push(obj)

})

.on('end', function() {

resolve(temp)

})

})


let writeStream = fs.createWriteStream('./output_0.ndjson')

const serialize = ndjson.stringify()

serialize.on('data', function(line) {

// line is line of stringified JSON with newline delimiter the end

writeStream.write(line, 'utf-8')


})


writeStream.on('finish', () => {

console.log('wrote all data to file')

})


data = data.forEach((item)=> {

let newItem = {

...item

}



newItem = rebuildFileAssetUrls(newItem)


serialize.write(newItem)


})




serialize.end()



})()

leaving this script here for anyone who have this problem again.

for this "amazing" community of 13 K members ! thank you very much!!!!
Nov 26, 2021, 3:55 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?