Ejemplo n.º 1
0
        public async Task <IActionResult> UploadFileAsync(string fileHash)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(fileHash))
                {
                    return(BadRequest());
                }

                var fullPath = VolumeHelper.GetFullPathFromHash(fileHash, true);

                using var readStream = Request.Body;

                if (System.IO.File.Exists(fullPath))
                {
                    System.IO.File.Delete(fullPath);
                }

                using var writeStream = System.IO.File.OpenWrite(fullPath);
                await readStream.CopyToAsync(writeStream);

                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 2
0
        public IActionResult DeleteFile(string fileHash)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(fileHash))
                {
                    return(BadRequest());
                }

                var fullPath = VolumeHelper.GetFullPathFromHash(fileHash, true);

                if (fullPath == null)
                {
                    return(BadRequest());
                }

                System.IO.File.Delete(fullPath);

                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 3
0
        public IActionResult DownloadFileAsync(string fileHash)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(fileHash))
                {
                    return(BadRequest());
                }

                var fullPath = VolumeHelper.GetFullPathFromHash(fileHash, true);

                if (fullPath == null)
                {
                    return(BadRequest());
                }

                return(File(fullPath, GetContentType(fullPath)));
            }
            catch
            {
                return(BadRequest());
            }
        }