public static async Task <string> Upload(ShareFileClient sfClient, Folder destinationFolder) { var file = System.IO.File.Open("SampleFileUpload.txt", FileMode.OpenOrCreate); var uploadRequest = new UploadSpecificationRequest { FileName = "SampleFileUpload.txt", FileSize = file.Length, Details = "Sample details", Parent = destinationFolder.url }; var uploader = sfClient.GetAsyncFileUploader(uploadRequest, file); var uploadResponse = await uploader.UploadAsync(); return(uploadResponse.First().Id); }
public async Task <bool> UploadFile(Stream stream, string parentFolderId, string fileName) { if (_client == null) { _client = await GetShareFileClient(); } var parentFolder = (Folder)await _client.Items.Get(BuildUriFromId(parentFolderId), false).ExecuteAsync(); var uploadRequest = new UploadSpecificationRequest { FileName = fileName, FileSize = stream.Length, Details = string.Empty, Parent = parentFolder.url, Overwrite = true }; var uploader = _client.GetAsyncFileUploader(uploadRequest, new PlatformFileStream(stream, stream.Length, fileName)); var uploadResponse = await uploader.UploadAsync(); return(uploadResponse.FirstOrDefault() != null); }