OneDrive / onedrive-api-docs

Official documentation for the OneDrive API
MIT License
447 stars 228 forks source link

New Error: "Name from path does not match name from body" when uploading large file with OneDriveLargeFileUploadTask #1790

Closed docu-bill closed 3 months ago

docu-bill commented 3 months ago

I have just started to get this error recently... similar code used to work. Has anything changed in the client or Graph API.

  const graphUrl = `/drives/${driveId}/items/${folderId}:/${fileName}:/createUploadSession`
  const options: OneDriveLargeFileUploadOptions = {
    fileName,
    rangeSize: 1024 * 1024,
    uploadEventHandlers,
    uploadSessionURL: graphUrl
  }
  const stats: fs.Stats = fs.statSync(sourcePath)
  const totalsize = stats.size
  return await new Promise<shortDocumentDescription>((resolve, reject) => {
    fs.readFile(sourcePath, async(err: NodeJS.ErrnoException | null, data: Buffer) => {
      if (err) reject(err)
      const fileObject: FileObject<Buffer> = {
        content: data,
        name: fileName,
        size: totalsize,
        sliceFile: (range: Range): Buffer => {
          return Buffer.from(data, range.minValue, range.maxValue-range.minValue);
        },
      }
      logger.debug("Creating task")
      const uploadTask = await OneDriveLargeFileUploadTask.createTaskWithFileObject(
                                                        client, fileObject, options)
      ...

    })
  })
}

This throws an error with message: "Name from path does not match name from body"

I was using fs.readFileSync and got the same error.

I am confident that my driveId and folderId are correct as they work for small files ie:

const graphUrl = `/drives/${driveId}/items/${folderId}:/${filename}:/content`

Category

Expected or Desired Behavior

I expect that I can create the task without it throwing and error

Observed Behavior

Error thrown on task creation

Steps to Reproduce

Try to upload a large file with a session.

Sorry if this is the wrong repository.