-
Notifications
You must be signed in to change notification settings - Fork 382
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
Comments
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible. |
Thank you for submitting your first issue to this project. |
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! 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 |
…oid 409 error As pr. issue pnp#1644 there's an issue when uploading multiple attachments at the same time to the same listitem
@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 |
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
The text was updated successfully, but these errors were encountered: