Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

LargeFileUploadTask documentation improvements for Client initialization #449

Copy link
Copy link
@kairiruutel

Description

@kairiruutel
Issue body actions

Would be useful to have an example in documentation about how to implement the LargeFileUploadTask with correct Client initialisation in regard of authorisation. Currently it is not clear that a new Client has to be initialised with authtoken from the UploadSession response to prevent 401 error.

Adding code example how I got it working:

const Url = require('url').URL
const { Client, LargeFileUploadTask, FileUpload } = require('@microsoft/microsoft-graph-client');

const graphClient = Client.init({
    authProvider: callback => callback(null, authHeader.token),
});

const { id } = await createMessage(graphClient); // creates new message through /me/messages

const uploadSession = await LargeFileUploadTask.createUploadSession(
    graphClient,
    `/me/messages/${messageId}/attachments/createUploadSession`,
    {
	AttachmentItem: {
		attachmentType: 'file',
		name: file.name,
		size: file.size,
	},
    }
);
const uploadUrl = new Url(uploadSession.url);
const uploadUrlAuthToken = uploadUrl.searchParams.get('authtoken');

const uploadClient = Client.init({
	authProvider: (done) => done(null, uploadUrlAuthToken)
});

const uploadTask = new LargeFileUploadTask(
	uploadClient,
	new FileUpload(
		file.content,
		file.name,
		file.size
	),
	uploadSession,
	{
		rangeSize: 5 * 1024 * 1024
	}
);

await uploadTask.upload();

AB#9349

Reactions are currently unavailable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.