Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/lib/load/load-files.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {readFiles, uploadFiles} from '@directus/sdk'
import {ux} from '@oclif/core'
import {FormData} from 'formdata-node'
import {readFileSync} from 'node:fs'
import { readFiles, uploadFiles } from '@directus/sdk'
import { ux } from '@oclif/core'
import { FormData } from 'formdata-node'
import { readFileSync } from 'node:fs'
import path from 'pathe'

import {DIRECTUS_PINK} from '../constants.js'
import {api} from '../sdk.js'
import { DIRECTUS_PINK } from '../constants.js'
import { api } from '../sdk.js'
import catchError from '../utils/catch-error.js'
import readFile from '../utils/read-file.js'

Expand Down Expand Up @@ -39,14 +39,15 @@ export default async function loadFiles(dir: string) {
await Promise.all(filesToUpload.map(async asset => {
const fileName = asset.filename_disk
const assetPath = path.resolve(dir, 'assets', fileName)
const fileStream = new Blob([readFileSync(assetPath)], {type: asset.type})
const fileStream = new Blob([readFileSync(assetPath)], { type: asset.type })

const form = new FormData()
form.append('id', asset.id)

if (asset.title) form.append('title', asset.title)
if (asset.description) form.append('description', asset.description)
if (asset.folder) form.append('folder', asset.folder)
if (asset.type) form.append('type', asset.type)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line that fixes the error I was facing when applying the AgencyOS template. See screenshot:

image

In text:

 ›   Warning: Directus Error: Invalid payload. "type" is required. (Status: 400) {"reason":"\"type\" is 
 ›   required","code":"INVALID_PAYLOAD"}
-- Request failed with status 400. Not retrying. Directus Error: Invalid payload. "type" is required. (Status: 400) {"reason":"\"type\" is required","code":"INVALID_PAYLOAD"}


form.append('file', fileStream, fileName)

Expand Down