public async Task <IActionResult> Index(string accountUrl = null, string container = null, string objectName = null) { if (!_TokenService.HasToken) { return(View("/Views/Home/Index.cshtml")); } if (accountUrl.IsNullOrEmpty()) { var authRes = await _SwiftService.AuthenticateTokenAsync(_TokenService.Token.AuthAPIV3EndPoint, _TokenService.Token.Token); return(View("/Views/Explorer/EnterAccountUrl.cshtml", authRes)); } _SwiftService.InitToken(_TokenService.Token.Token); if (container.IsNullOrEmpty()) { var ss = await _SwiftService.AccountListContainersAsync(accountUrl); return(View("/Views/Explorer/GetAccount.cshtml", ss)); } if (objectName.IsNullOrEmpty()) { var ss = await _SwiftService.ContainerGetAsync(accountUrl, container); return(View("/Views/Explorer/GetContainer.cshtml", ss)); } { var ss = await _SwiftService.ObjectHeadAsync(accountUrl, container, objectName); return(View("/Views/Explorer/GetObject.cshtml", ss)); } }
AddFile(IFormFile file, string accountUrl, string container, string prefix = null, string fileName = null, string fileExtension = null, string contentType = null, UploadOptions options = null) { options = options ?? DefaultOptions; if (file == null || file.Length == 0) { return(UploadStatus.NoFileProvided, null); } if (file.Length / 1024 > options.SizeLimitKb) { return(UploadStatus.FileTooBig, null); } _SwiftService.InitToken(_TokenService.Token.Token); fileName = fileName ?? file.FileName; var ext = System.IO.Path.GetExtension(fileName); fileExtension = fileExtension ?? ext; if (_FileExtensionContentTypeProvider.TryGetContentType(fileName, out string contentType2)) { contentType = contentType ?? contentType2; } else { contentType = contentType ?? "unknown"; } UploadedFile uf = new UploadedFile() { ContentType = contentType, Extension = fileExtension, FileName = fileName, UploadId = Guid.NewGuid(), Size = file.Length, //Data =, }; byte[] data = null; using (var fs1 = file.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); data = ms1.ToArray(); var resp = await _SwiftService.ObjectPutAsync(accountUrl, container, $"{prefix}{uf.FileName}", data, contentType); //var resp=await _SwiftService.ObjectPutAsync(accountUrl, container, $"{prefix}{uf.FileName}", fs1, contentType); } return(UploadStatus.Ok, uf); }
public async Task <IActionResult> Download(string accountUrl, string container, string objectName) { if (!_TokenService.HasToken || accountUrl.IsNullOrEmpty() || container.IsNullOrEmpty() || objectName.IsNullOrEmpty()) { return(RedirectToRoute(Routes.GET_Home_Route)); } _SwiftService.InitToken(_TokenService.Token.Token); var ss = await _SwiftService.ObjectGetAsync(accountUrl, container, objectName); if (!ss.IsSuccess) { return(RedirectToRoute(Routes.GET_Home_Route)); } if (Request.GetQueryParameter("disposition").Count > 0) { Response.Headers["Content-Disposition"] = Request.GetQueryParameter("disposition"); } Response.ContentType = ss.ContentType; Response.ContentLength = ss.ContentLength; return(File(ss.ObjectStreamContent, ss.ContentType.IfNullOrEmpty("application/octet-stream"), objectName)); }