Hi, it's possible to seed data from a remote url?
I'm migrating a website with 50k+ posts to payload, but can't find a way to upload the images of each post with the previous url.
And also, I would like to know how to transform text build in plain html (Only <p> tags) to the format that require payload to seed the data.
Thanks!
Yes, you can do this for sure
you can write a simple node script to seed data using payload's local API
and you can even upload files with the local api as well
const payload = require('payload');
require('dotenv').config();
const {
PAYLOAD_SECRET_KEY,
MONGO_URL,
} = process.env;
payload.init({
secret: PAYLOAD_SECRET_KEY,
mongoURL: MONGO_URL,
local: true,
})
const seed = async () => {
// fetch your documents
const docs = await fetch('https://my-api.com').then(res => res.json())
const promises = docs.map(async (doc) => {
await payload.create({
collection: 'docs',
data: doc
});
})
await Promise.all(promises)
process.exit(0);
}
seed();
something like that
and then you'd call the script like
node seed.js
or whatever your file is called
I understand the use of the local API, but I got problems to upload my old images to /media.
Also I realize that the tree schema of rich content is really different from my old <p> website structure
Sorry if I didn't communicate well on the first message. I'm not native, so it's probably unclear.
const result = await payload.create({
collection: "media",
data: {
alt: "your alt description",
},
filePath: path.resolve(__dirname, "./assets/logo.png"),
});
You can transform your data at
https://my-api.com/your-transformto fit payload cms.
Thanks!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.