I am trying to upload pdf files of size 20 MB,30 MB etc. For this I am creating the upload session, creating a callback that is invoked after each slice is uploaded and then finally uploading the file.
First I read the bytes in memory stream and then Taking slice size as 320*1024 and then do uploading.
But my file is uploading with no content. The reason is all bytes are not uploading. if my file size is 35303569bytes, only 35061760 bytes are uploaded. No error is coming. When I check the file I could see the file in SharePoint site and when I open it there is no content.
Could anyone suggest me where I am going wrong or missing in the code.
Below is the code:
using (ms=new MemoryStream())
{
byte[] bytes = System.Convert.FromBase64String(data);
ms.Write(bytes, 0, bytes.Length);
ms.Seek(0,SeekOrigin.Begin);
var uploadSession =await graphclient.Sites[SiteId].Drive.Root.ItemWithPath(docfilename).CreateUploadSession().Request().PostAsync();
var maxschinksize=320*1024;
var largeuploadtask=new LargeUploadTask<DriveItem>(uploadsession,ms,maxchunksize)//ms is the memory stream in which I am reading the bytes.
IProgress<long> uploadProgress=new Progress<long>(uploadbytes=>
{
}
uploadResult=await largeuploadtask.UploadAsync(uploadprogress);
}
There was some issue within my code only. I was reading the content of file and it's encoding was also changing. That means content that I was converting into base64string is not the original content. All bytes were uploading, problem was with content. Now, I used online converter to convert file to base64 string and it worked.