I have a project to upload files to Sharepoint using REST API ( POST). I am using vb.net and RestSharp. Code is below. this code is working. I am able to do with the small Text file only and the file is getting properly upload into Sharepoint. But when it comes to another file format ( XLS, XLSX, PDF, JOG, Doc ..etc) with a file size greater than 1 MB file is getting uploaded with it, not in a readable format. I tried to upload a ZIP file for 55 MB it is getting Uploaded. But When I download the same uploaded file I am not able to read it. Can anyone please help me, to get this fixed? ** I would need a solution to upload any file format for any size ( In my project I will not use any file more than 500 MB for upload. )
Below is the code is tried.
Public Sub UploadFile2()
Dim FullfileName As String = "E:\Desktop\try\FileToUpload.xlsx"
Dim NewFileName As String = "NewFile.xlsx"
Dim uploadFileUrl As String = SiteUrl + "_api/web/lists/getByTitle('Documents')/RootFolder/Files/Add(url='" + NewFileName + "', overwrite=true)"
Dim client = New RestClient(uploadFileUrl) With {
.Timeout = -1
}
Dim UploadRequest = New RestRequest(Method.POST)
UploadRequest.AddHeader("Accept", "application/json;odata=verbose")
UploadRequest.AddHeader("X-RequestDigest", DigestValue)
UploadRequest.AddHeader("Authorization", "Bearer " + AccessToken)
UploadRequest.AddHeader("Content-Type", "multipart/form-data")
UploadRequest.AlwaysMultipartFormData = True
UploadRequest.AddFile("FileName", FullfileName)
UploadResponse = client.Execute(UploadRequest)
End Sub