/// <summary> /// Write blob /// </summary> /// <param name="container"></param> /// <param name="blobName"></param> /// <param name="blob"></param> /// <param name="parallelUploadFactor"></param> /// <param name="chunkSizeInMB"></param> public void WriteBlob(string containerName, string blobName, Blob blob, int parallelUploadFactor = 1, int chunkSizeInMB = 4) { var url = containerName + "/" + blob.Name; url = url.Replace(oneDriveHelper.OneDrivePrefix(), ""); if (destinationDirectory == null) { // check if target folder exists. // if not, create it. destinationDirectory = oneDriveHelper.GetOneDriveDirectory(containerName); if (destinationDirectory == null) { destinationDirectory = oneDriveHelper.CreateFolder(url); } } var urlTemplate = @"https://apis.live.net/v5.0/{0}/files/{1}?access_token={2}"; var requestUrl = string.Format(urlTemplate, destinationDirectory.Id, blobName, accessToken); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl); request.Method = "PUT"; Stream dataStream = request.GetRequestStream(); Stream inputStream = null; // get stream to data. if (blob.BlobSavedToFile) { inputStream = new FileStream(blob.FilePath, FileMode.Open); } else { inputStream = new MemoryStream(blob.Data); } int bytesRead; int readSize = 64000; int totalSize = 0; byte[] arr = new byte[readSize]; do { bytesRead = inputStream.Read(arr, 0, readSize); if (bytesRead > 0) { totalSize += bytesRead; dataStream.Write(arr, 0, bytesRead); } }while (bytesRead > 0); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); }
/// <summary> /// Write blob /// </summary> /// <param name="container"></param> /// <param name="blobName"></param> /// <param name="blob"></param> /// <param name="parallelUploadFactor"></param> /// <param name="chunkSizeInMB"></param> public void WriteBlob(string containerName, string blobName, Blob blob, int parallelUploadFactor = 1, int chunkSizeInMB = 4) { var url = containerName + "/" + blob.Name; url = url.Replace(oneDriveHelper.OneDrivePrefix(), ""); if (destinationDirectory == null) { // check if target folder exists. // if not, create it. destinationDirectory = oneDriveHelper.GetOneDriveDirectory(containerName); if (destinationDirectory == null) { destinationDirectory = oneDriveHelper.CreateFolder(url); } } var urlTemplate = @"https://apis.live.net/v5.0/{0}/files/{1}?access_token={2}"; var requestUrl = string.Format(urlTemplate, destinationDirectory.Id, blobName, accessToken); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl); request.Method = "PUT"; Stream dataStream = request.GetRequestStream(); Stream inputStream = null; // get stream to data. if (blob.BlobSavedToFile) { inputStream = new FileStream(blob.FilePath, FileMode.Open); } else { inputStream = new MemoryStream(blob.Data); } int bytesRead; int readSize = 64000; int totalSize = 0; byte[] arr = new byte[readSize]; do { bytesRead = inputStream.Read( arr,0, readSize); if (bytesRead > 0) { totalSize += bytesRead; dataStream.Write(arr, 0, bytesRead); } } while ( bytesRead > 0); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); }