public async Task <IActionResult> GetObject()
        {
            try
            {
                await _OSSService.GetObjectAsync(_bucketName, "PHOTO-1.jpg", (stream) =>
                {
                    using (FileStream fs = new FileStream(@"D:\Temp\PHOTO-1.jpg", FileMode.Create, FileAccess.Write))
                    {
                        stream.CopyTo(fs);
                        fs.Close();
                    }
                });

                return(Json("OK"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetObject()
        {
            try
            {
                if (System.IO.File.Exists(_downloadFilePath))
                {
                    System.IO.File.Delete(_downloadFilePath);
                }

                await _ossService.GetObjectAsync(_bucketName, _objectFilePath, _downloadFilePath);

                if (System.IO.File.Exists(_downloadFilePath))
                {
                    return(Json(new ResultObject()
                    {
                        Status = true,
                        Message = $"文件【{_objectFilePath}】下载成功,路径:{_downloadFilePath}"
                    }));
                }
                else
                {
                    return(Json(new ResultObject()
                    {
                        Status = false,
                        Message = $"文件【{_objectFilePath}】下载失败"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ResultObject()
                {
                    Status = false,
                    Message = ex.Message
                }));
            }
        }