pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
749 stars 305 forks source link

Uploading files into folder in batching - getting IO Error occured #2923

Closed sliziky closed 7 months ago

sliziky commented 7 months ago

What version of PnPjs library you are using

3.x

Minor Version Number

3.21.0

Target environment

All

Additional environment details

NodeJS v16.14.0

Question/Request

I am trying to upload multiple files into the library using batch but I keep getting these 500 Errors saying IO Error Occurred. When using the same non-batch approach it works, it is some kind of shp internal problem or am I using batch wrong? Thanks

Working Non-batch version

const photoChunks = _.chunk(images, 100);
      await Promise.all(
        photoChunks.map(async (chunk) => {
          await Promise.all(
            chunk.map(async (image: any) => {
              const fileNamePath = encodeURI(image.path).replace(/%20/g, " ");
              await sp.web
                .getFolderByServerRelativePath(`${libraryName}/${folderName}`)
                .files.addUsingPath(fileNamePath, image.file, {
                  Overwrite: true
                });
            })
          );
        })
      );
    } catch (e) {}

Non-working Batch version

      const responses: IFileAddResult[] = [];
      const photoChunks = _.chunk(images, 100);
      await Promise.all(
        photoChunks.map(async (chunk) => {
          const [batchedSP, execute] = sp.web.batched();
          await Promise.all(
            chunk.map(async (image: any) => {
              const fileNamePath = encodeURI(image.path).replace(/%20/g, " ");
              batchedSP
                .getFolderByServerRelativePath(`${libraryName}/${folderName}`)
                .files.addUsingPath(fileNamePath, image.file, {
                  Overwrite: true
                })
                .then((response) => {
                  responses.push(response);
                })
                .catch((e) => console.log(e));
            })
          );
          await execute();
        })
      );
    } catch (e) {}
image
juliemturner commented 7 months ago

Sorry, that's a documentation bug, in general we have the "Batching Not Supported" flag everywhere but clearly missed that section. I've added the banner for the next documentation build.

juliemturner commented 7 months ago

I'm going to close this issue as answered. If you have further issues, please feel free to create a new issue and reference this one.

github-actions[bot] commented 7 months ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.