Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListItemAttachments - Inconsistent file handling #1644

Closed
rikkerorbak opened this issue Sep 14, 2023 · 4 comments · Fixed by #1709
Closed

ListItemAttachments - Inconsistent file handling #1644

rikkerorbak opened this issue Sep 14, 2023 · 4 comments · Fixed by #1709
Assignees
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Milestone

Comments

@rikkerorbak
Copy link

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your
needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the documentation to see if your question is already addressed there. This will help us ensure our documentation is up to date.

Category

[ ] Enhancement

[x?] Bug

[x] Question

Version

Please specify what version of the library you are using: [ 3.15.0 ]

Expected / Desired Behavior / Question

I am experiencing inconsistent uploading and deletion of files. Often, perhaps only when creating a new list item, a few files will often not be uploaded. Checking the dev tools, the addFile-method fails with a 404 or 409.
I don't know if my code is the issue (this is my first webpart, and I am generally not a terribly experienced developer), but I can't figure out what the issue is. Things seem to work fine on an existing item.
Another observation is that when attaching files to an existing list item, I see the loading animation running, but I don't see that when attaching to a new list item; not sure if that says anything.

Regarding deletion, I sometimes experience that a file, often the last after having added a few, does not get deleted but instead remains in the container.

Thank you so much! I've spent days troubleshooting this and really hope I can get help figuring it out!

/Rikke

@ghost
Copy link

ghost commented Sep 14, 2023

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Sep 14, 2023
@github-actions
Copy link

Thank you for submitting your first issue to this project.

@rikkerorbak rikkerorbak changed the title ListItemAttachment - Inconsistent file handling ListItemAttachments - Inconsistent file handling Sep 19, 2023
@Tanddant
Copy link
Contributor

I did a bit of digging on this one - it seems to be related to a concurrency issue.

I can't find any docs confirming it, but several others confirm it:

When uploading attachments Microsoft doesn't like us uploading multiple files at the same time

Quick code the validate:

import { sp, IAttachmentAddResult } from "@pnp/sp/presets/all";

(async () => {

  const file = sp.web.lists.getByTitle("Generic list").items.getById(3).attachmentFiles;
  const promises: Promise<IAttachmentAddResult>[] = [];
  for (let x = 1; x <= 100; x++) {
    promises.push(file.add(`${x}.txt`, "This is an attachemnt"));
  }

  const parsed: IAttachmentAddResult[] = await Promise.all(promises);

  for (let p of parsed) {
    console.log(p)
  }


})().catch(console.log)

Bingo!

image

I guess the solution would be to change this

to something along the lines of

public async uploadAttachments(itemId: number): Promise<void> {
  if (this.state.filesToUpload) {
    for (const file of this.state.filesToUpload) {
      await this._spservice.addAttachment(
        this.props.listId,
        itemId,
        file.name,
        file,
        this.props.webUrl);
    }
  }
  return new Promise<void>((resolve, reject) => {
    this.setState({
      filesToUpload: [],
      itemId: itemId
    }, () => this.loadAttachments().then(resolve));
  });
}

@joelfmrodrigues will you look this over and I'll be happy to submit a PR resolving the issue - it will slow down the experience, but will resolve the issue when adding multiple files

Tanddant added a commit to Tanddant/sp-dev-fx-controls-react that referenced this issue Sep 19, 2023
…oid 409 error

As pr. issue pnp#1644 there's an issue when uploading multiple attachments at the same time to the same listitem
@michaelmaillot michaelmaillot added status:working-on-it Known issue / feature being addressed. Will use other "status:*" labels & comments for more detail. type:bug and removed Needs: Triage 🔍 labels Sep 25, 2023
@joelfmrodrigues joelfmrodrigues added this to the 3.16.0 milestone Oct 24, 2023
@joelfmrodrigues joelfmrodrigues added status:fixed-next-drop Issue will be fixed in upcoming release. and removed status:working-on-it Known issue / feature being addressed. Will use other "status:*" labels & comments for more detail. labels Oct 24, 2023
@joelfmrodrigues
Copy link
Collaborator

@rikkerorbak the PR to fix this is now merged and the fix will be in the beta release in a few minutes. If you have the chance to try this, please let us know if it's been fixed

@AJIXuMuK AJIXuMuK mentioned this issue Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants