使用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 Conflict\n\nYour 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.
它实际上是成功添加了一个文件,但不是2个文件,并在上面显示了此错误。
我尝试使用sp.Batched()
方法: https://pnp.github.github.io/pnpjs/pnpjs/pnpjs/pnpjs/sp/attachments/attachments/attachments/attachments/pthachments/pthachent/p添加杂物 但是不确定如何使用它,但是我想知道为什么上面的代码显示此错误?
I'm using sp/pnp to submit a list item with multiple attachments:
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);
});
});
}
});
};
This is showing:
Save Conflict\n\nYour 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.
It actually adds one file successfully, but not 2 files and shows this error above.
I've attempted to use the sp.batched()
method supplied here:
https://pnp.github.io/pnpjs/sp/attachments/#add-multiple
But am unsure of how to use it, but I would like to know why my code above shows this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试同步添加这些文件 - 在sp.web之前等待(在files.foreach周期中)。我认为,如果您有更多文件,则所有REST呼叫都会同时触发 - 可能会导致错误。
Try to add those files synchronously - put await before sp.web (in files.forEach cycle). I assume that if you have more files, all rest call are fired simultaneously - may cause error.