Skip to content

LargeFileUploadTask is ending with PassThrough stream instead of saying JSON response with id #359

@hilarudeens

Description

@hilarudeens

Bug Report

I'm using msgraph-sdk-javascript in NodeJs and try attach a document in Outlook email. The issue is, LargeFileUploadTask.uploadSlice function returns PassThrough readable stream on end of file upload instead of JSON response with id.

Prerequisites

  • [ Yes] Can you reproduce the problem?
  • [Yes ] Are you running the latest version?
    I'm using 2.1.1 as of 19th Nov 2020
  • [Yes ] Are you reporting to the correct repository?
  • Did you perform a cursory search?

Steps to Reproduce

  1. Create an Outlook draft message by usingPostman.

  2. Create a simple HttpTrigger Azure Function and Add following code in Azure Function handler.

const saveAttachment = async (oid, tenantId, messageId, file) => {
    // getClient is just creating client with GraphToken generate authProvider.
    // authProvider is doing client-credential flow to generate token.
    const client = await getClient(tenantId);

    const uploadSessionPayload = {
        AttachmentItem: {
          attachmentType: 'file',
          name: file.filename,
          size: file.size
        }
    };

    const uploadSession = await LargeFileUploadTask.createUploadSession(
        client, 
        `/users/${oid}/messages/${messageId}/attachments/createUploadSession`,
        uploadSessionPayload,
    );
    const fileObject = {
        content: file.data,
        name: file.filename,
        size: file.size
    };

    const { url: uploadUrl } = uploadSession; 
    const uploadUrlTokens = uploadUrl.split('?');
    const uploadUrlAuthToken = uploadUrlTokens[1].replace('authtoken=', '');
    const uploadClient = Client.init({
        authProvider: (done) => done(null, uploadUrlAuthToken),
        debugLogging: true
    });

    const uploadTask = new LargeFileUploadTask(uploadClient, fileObject, uploadSession, {
        rangeSize: 5 * 1024 * 1024,
    });

    const uploadResponse = await uploadTask.upload();
    return uploadResponse;
};
  1. Execute AzureFunction in Visual Studio Code.

  2. Call HttpTrigger from Postman

Expected behavior:
Large file should be uploaded in sequential PUT call. In end of all chunks upload, LargeFileUploadTask.uploadSlice function should give response with 'id'

ShouldEndUpFileJsonResponseWithIdProperty

Actual behavior:
LargeFileUploadTask.uploadSlice function is giving NodeJs ReadableStream.

Additional Context

LargeFileUploadResponse1

LargeFileUploadResponseEndOfUpload

Code Line:

AB#7549

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions