Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
38 lines
994 B
Plaintext
38 lines
994 B
Plaintext
import { serialize } from 'object-to-formdata';
|
|
import { reduceFieldsToValues } from 'payload/shared';
|
|
export async function createFormData(formState = {}, overrides = {}, collectionSlug, uploadHandler) {
|
|
const data = reduceFieldsToValues(formState, true);
|
|
let file = data?.file;
|
|
if (file) {
|
|
delete data.file;
|
|
}
|
|
if (file && typeof uploadHandler === 'function') {
|
|
let filename = file.name;
|
|
const clientUploadContext = await uploadHandler({
|
|
file,
|
|
updateFilename: value => {
|
|
filename = value;
|
|
}
|
|
});
|
|
file = JSON.stringify({
|
|
clientUploadContext,
|
|
collectionSlug,
|
|
filename,
|
|
mimeType: file.type,
|
|
size: file.size
|
|
});
|
|
}
|
|
const dataWithOverrides = {
|
|
...data,
|
|
...overrides
|
|
};
|
|
const dataToSerialize = {
|
|
_payload: JSON.stringify(dataWithOverrides),
|
|
file
|
|
};
|
|
return serialize(dataToSerialize, {
|
|
indices: true,
|
|
nullsAsUndefineds: false
|
|
});
|
|
}
|
|
//# sourceMappingURL=createFormData.js.map |