public static string GetMeta(this SwiftBaseResponse rsp, string metaName) { if (rsp.Headers == null) { return(null); } var objectMetaKey = string.Format(SwiftHeaderKeys.ObjectMetaFormat, metaName); if (rsp.Headers.ContainsKey(objectMetaKey)) { return(rsp.Headers[objectMetaKey]); } var containerMetaKey = string.Format(SwiftHeaderKeys.ContainerMetaFormat, metaName); if (rsp.Headers.ContainsKey(containerMetaKey)) { return(rsp.Headers[containerMetaKey]); } var accountMetaKey = string.Format(SwiftHeaderKeys.AccountMetaFormat, metaName); if (rsp.Headers.ContainsKey(accountMetaKey)) { return(rsp.Headers[accountMetaKey]); } return(null); }
public static int UploadFile(PutOptions options, Client client, bool showProgress = true) { var stopwatch = Stopwatch.StartNew(); long bufferSize = Convert.ToInt64(ByteSize.FromMegabytes(options.BufferSize).Bytes); if (!File.Exists(options.File)) { Logger.LogError($"File not found {options.File}"); return 404; } if (options.ToLower) { options.Container = options.Container.ToLowerInvariant(); if (!string.IsNullOrEmpty(options.Object)) { options.Object = options.Object.ToLowerInvariant(); } } if (showProgress) Logger.Log($"Uploading {options.File} to {options.Object}"); var response = new SwiftBaseResponse(); var fileName = Path.GetFileName(options.File); response = client.PutContainer(options.Container).Result; if (!response.IsSuccess) { Logger.LogError($"Put container error {response.Reason}"); return 500; } using (var stream = File.OpenRead(options.File)) { if (showProgress) Console.Write($"\rUploading..."); var headers = new Dictionary<string, string> { { $"X-Object-Meta-Filename", fileName }, { $"X-Object-Meta-Contenttype", MimeTypeMap.GetMimeType(Path.GetExtension(options.File)) } }; response = client.PutLargeObject(options.Container, options.Object, stream, headers, (chunk, bytesRead) => { if (showProgress) Console.Write($"\rUploaded {((chunk * options.BufferSize).Megabytes() + bytesRead.Bytes()).Humanize("MB")}"); }, Convert.ToInt64(ByteSize.FromMegabytes(options.BufferSize).Bytes)).Result; if (!response.IsSuccess) { Logger.LogError($"Uploading error {response.Reason}"); return 500; } if (showProgress) Console.Write($"\rUpload done in {stopwatch.ElapsedMilliseconds.Milliseconds().Humanize()}"); if (showProgress) Console.Write(Environment.NewLine); } return 0; }
public static int UploadFile(PutOptions options, Client client, bool showProgress = true) { var stopwatch = Stopwatch.StartNew(); long bufferSize = Convert.ToInt64(ByteSize.FromMegabytes(options.BufferSize).Bytes); if (!File.Exists(options.File)) { Logger.LogError($"File not found {options.File}"); return(404); } if (options.ToLower) { options.Container = options.Container.ToLowerInvariant(); if (!string.IsNullOrEmpty(options.Object)) { options.Object = options.Object.ToLowerInvariant(); } } if (showProgress) { Logger.Log($"Uploading {options.File} to {options.Object}"); } var response = new SwiftBaseResponse(); var fileName = Path.GetFileName(options.File); response = client.PutContainer(options.Container).Result; if (!response.IsSuccess) { Logger.LogError($"Put container error {response.Reason}"); return(500); } using (var stream = File.OpenRead(options.File)) { if (showProgress) { Console.Write($"\rUploading..."); } var headers = new Dictionary <string, string> { { $"X-Object-Meta-Filename", fileName }, { $"X-Object-Meta-Contenttype", MimeTypeMap.GetMimeType(Path.GetExtension(options.File)) } }; response = client.PutLargeObject(options.Container, options.Object, stream, headers, (chunk, bytesRead) => { if (showProgress) { Console.Write($"\rUploaded {((chunk * options.BufferSize).Megabytes() + bytesRead.Bytes()).Humanize("MB")}"); } }, Convert.ToInt64(ByteSize.FromMegabytes(options.BufferSize).Bytes)).Result; if (!response.IsSuccess) { Logger.LogError($"Uploading error {response.Reason}"); return(500); } if (showProgress) { Console.Write($"\rUpload done in {stopwatch.ElapsedMilliseconds.Milliseconds().Humanize()}"); } if (showProgress) { Console.Write(Environment.NewLine); } } return(0); }