使用sp/pnp最新版本向列表项提交多个文件附件时出错



我使用sp/pnp提交带有多个附件的列表项:

export const CreateListItem = async (listName: string, item: any, files: File[]) => {
const record = item as unknown as Record<string, any>;
return await sp.web.lists.getByTitle(listName).items.add(record).then(async (r) => {
var fileInfos: IAttachmentFileInfo[] = [];
if (files) {
files.forEach(async file => { 
sp.
web.
lists.
getByTitle(listName).
items.
getById(r.data.Id).
attachmentFiles.add(file.name, file).
then(res => {
console.log(res);
});
});
}
});
};

这显示:

Save ConflictnnYour changes conflict with those made concurrently by another user. 
If you want your changes to be applied, 
click Back in your Web browser, refresh the page, and resubmit your changes.

它实际上成功地添加了一个文件,但没有添加两个文件,并在上面显示了这个错误。

我尝试使用此处提供的sp.batched()方法:https://pnp.github.io/pnpjs/sp/attachments/#add-倍数但我不确定如何使用它,但我想知道为什么我上面的代码显示这个错误?

尝试同步添加这些文件-将wait放在sp.web之前(在files.forEach循环中(。我认为,如果您有更多的文件,所有的rest调用都会同时启动,这可能会导致错误。

最新更新