使用SP/PNP最新版本将多个文件附件提交到列表项目时获取错误

发布于 2025-01-18 18:47:52 字数 1304 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦晓ヶ微光ヅ倾城 2025-01-25 18:47:52

尝试同步添加这些文件 - 在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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文