-
Notifications
You must be signed in to change notification settings - Fork 233
Closed
Description
Hello,
This issue was solved in issue #456 by @nikithauc for Node API but now I would like to figure out how to do this is in React.
I am trying to upload a file (> 4 MB) directly from React to SharePoint with the Microsoft Graph API. Here is my code below.
I keep getting the following error:
Please provide the Readable Stream content, name of the file and size of the file
- /src/tasks/FileUploadTask/FileObjectClasses/FileUpload.ts:28
- I think it is because I am uploading a file (instead of a readable stream) to - new FileUpload(file,name,size).
Can I turn a file to a readable stream in React?
Could you assist with this? If this not possible is the only other way from an API on the backend? How would I transfer my access code to the backend?
``
// Function 1 - GET UPLOADED FILE FROM USER IN REACT
const file1 = e.target.files[0]
console.log('instance of file', file1 instanceof File) // TRUE
uploadLargeDocument(app.authProvider, fileObj)
// Function 2 - UPLOAD FILE TO SHAREPOINT
const it_site_id = 'xyz'
const requestUrl = https://graph.microsoft.com/v1.0/sites/${it_site_id}/drive/items/root:/Code/doggy5:/createUploadSession
const payload = {
"@microsoft.graph.conflictBehavior": "replace",
"description": "description",
"fileSize": file.size,
"name": file.name
}
const uploadSession = await LargeFileUploadTask.createUploadSession(graphClient, requestUrl, payload);
// ERROR - Please provide the Readable Stream content, name of the file and size of the file
const fileObject = new FileUpload({
content: file,
name: file.name,
size: file.size
})
const task = new LargeFileUploadTask(graphClient, fileObject, uploadSession);
const response = task.upload();
return response
}`