예제 #1
0
        public async Task <IActionResult> DeleteFile([FromBody] Revision revision)
        {
            string path = Revision.GetFileServerPath(revision);

            System.IO.File.Delete(path);
            await _hubContext.Clients.All.SendAsync(revision.userName + " apagou um arquivo: " + revision.fileName);

            await _repo.RemoveOfRepository(revision);

            await Task.Yield();

            return(Ok());
        }
예제 #2
0
        public async Task <IActionResult> DownloadFile([FromBody] Revision revision)
        {
            string path = Revision.GetFileServerPath(revision);

            //var response = await System.IO.File.ReadAllBytesAsync(path);
            await _hubContext.Clients.All.SendAsync(revision.userName + " realizou o download um arquivo: " + revision.fileName);

            await Task.Yield();

            //return new FileContentResult(response ,"application/octet-stream");

            var stream = new FileStream(path, FileMode.OpenOrCreate);

            return(new FileStreamResult(stream, "appclication/octet-stream"));
        }
예제 #3
0
        public async Task <IActionResult> SendFile([FromBody] Revision revision)
        {
            string path = Revision.GetFileServerPath(revision);

            await _hubContext.Clients.All.SendAsync(revision.userName +
                                                    " iniciou uma transferencia de arquivo: " + revision.fileName);

            try{
                var encodedBytes = Convert.FromBase64String(
                    Convert.ToBase64String(System.Text.Encoding.Unicode.GetBytes(revision.fileData)));

                await System.IO.File.WriteAllBytesAsync(path, encodedBytes);
            }catch (Exception e) {
                return(BadRequest("Não foi possivel criar seu arquivo, seu animal"));
            }

            revision.LastModificationDate = DateTime.Now.ToString();

            await _repo.AddToRepository(revision);

            await _hubContext.Clients.All.SendAsync("Transferencia finalizada: " + revision.fileName);

            return(Ok());
        }