msgraph-sdk-javascript: Put File to One Drive Document results in corrupted file

Bug Report

the file is created, the file appears to be the correct size but when the file no matter the type is opened, xlsx, pdf, png, jpg - all are corrupted

Prerequisites

  • [ yes] Can you reproduce the problem?
  • [yes ] Are you running the latest version?
  • [ yes] Are you reporting to the correct repository?
  • [ yes] Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

[Description of the bug or feature] Using the following client script, we’re able to get the file, then we’re able to create the file, but the file is corrupt no matter if the mediatype is. Expected outcome is created file without corruption. the file size and type are correct, but the file is not downloadable or useable.

The bytes are correct and are derived from the file directly

` let driveItem = { // “@microsoft.graph.fileAttachment”:“https://graph.microsoft.com/v1.0/users/” + uid as string +“/mailFolders/”+folderId as string+“/messages/”+item.id as string+“/attachments/”+aitem.id+‘/value$’, // ‘@odata.mediaContentType’: item.contentType as string, // “id”: item.id as string, // “lastModifiedDateTime”: item.lastModifiedDateTime as string, // “fileType”:aitem.contentType as string, “name”: aitem.name as string, “contentType”: “text/plain”, “isInline”: aitem.isInline, // “contentId”: item.contentId as string, // “contentLocation”: item.contentLocation as string, “contentBytes”: aitem.contentBytes as string, file: {

             },
            '@microsoft.graph.conflictBehavior': 'rename',
            // '@odata.type': '#microsoft.graph.fileAttachment'
          }
        //  admin.storage().bucket('onedrive').create(driveItem).then(()=>{
        //   console.log()
        //  })
          console.log('DRIVE ITEM', driveItem)
          await client.api('/users/' + uid as string +'/drive/root:/'+folderName+'/'+aitem.name+':/content').put(driveItem).then(async (res_create)=>{
            console.log('RES_CREATE', res_create)
            creates the file as expected but the file is corrupt.
        })`

Console Errors: [Is there any console error] no error the file is created - but the file cannot be previewed nor can it be opened with its native application launcher. IE PDF, XLSX, JPG, PNG Screenshots: [If applicable, add screenshots to help explain your problem]

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on…] run script - above using client api, client Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

Additional Context

Add any other context about the problem here…

Usage Information

Request ID - Value of the requestId field if you are receiving a Graph API error response

SDK Version - [SDK version you are using] “@azure/identity”: “^3.1.3”, “@microsoft/microsoft-graph-client”: “^3.0.5”

  • Node (Check, if using Node version of SDK) v.16.4.0

Node Version - [The version of Node you are using]

  • Browser (Check, if using Browser version of SDK)

Browser Name - [The name of Browser that you are using for SDK] (Mac): chrome, safari Version - [The version of the browser you are using] Safari: Version 16.2 (18614.3.7.1.5) Chrome: Version 109.0.5414.119 (Official Build) (arm64)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

I removed .toString() and it appears to be working correctly. Let me test a few more times. If that is it - then we are good to go. I am to assume the problem is because I was not returning the buffer.from initially.

Okay sounds good