public async Task <IActionResult> DownloadAsync(string id) { var share = await _shareService.GetShareByIdAsync(id); var user = await _userService.GetUserByIdAsync(share.UserId); var sharedObjectsList = await _shareService.GetShareContentAsync(share); var fsoList = await _fsoService.GetFsoListByIdAsync(sharedObjectsList.Select(x => x.FsoId).ToArray()); var root = await _fsoService.CheckParentFso(fsoList); if (root == null) { return(BadRequest("Invalid request")); } string contentType; if (fsoList.Count == 1 && !fsoList[0].IsFolder) { contentType = _fsoService.GetMimeType(Path.GetExtension(fsoList[0].Name)); } else { contentType = _fsoService.GetMimeType(".zip"); } var extension = Path.GetExtension(fsoList[0].Name); var stream = await _fsoService.GetFileAsync(root, fsoList, user); return(File(stream, contentType)); }
public async Task <IActionResult> DownloadAsync() { var fsoIdcsv = Request.Form["fsoIdcsv"].ToString(); var user = await _userService.GetUserFromPrincipalAsync(this.User); if (string.IsNullOrEmpty(fsoIdcsv)) { return(BadRequest()); } int[] fsoIdArray = Array.ConvertAll(fsoIdcsv.Split(','), int.Parse); var fsoList = await _fsoService.GetFsoListByIdAsync(fsoIdArray); var root = await _fsoService.CheckParentFso(fsoList); if (root == null || !await _fsoService.CheckOwnerAsync(root, user)) { return(Forbid()); } string contentType; if (fsoList.Count == 1 && !fsoList[0].IsFolder) { contentType = _fsoService.GetMimeType(Path.GetExtension(fsoList[0].Name)); } else { contentType = _fsoService.GetMimeType(".zip"); } var extension = Path.GetExtension(fsoList[0].Name); var stream = await _fsoService.GetFileAsync(root, fsoList, user); return(File(stream, contentType)); }