diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json index b1308dcdc..6e7560e11 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json @@ -15,6 +15,7 @@ "Permission:Delete": "Delete", "Permission:Upload": "Upload", "Permission:Download": "Download", + "FileNotBeNullOrEmpty": "Upload file not be null!", "FileNotFound": "The specified file does not exist!", "PathNotFound": "The specified directory does not exist!", "FilePathNotFound": "The file or directory does not exist!", diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json index 57659a89f..278a99068 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json @@ -15,6 +15,7 @@ "Permission:Delete": "删除", "Permission:Upload": "上传", "Permission:Download": "下载", + "FileNotBeNullOrEmpty": "上传文件不能为空!", "FileNotFound": "指定的文件不存在!", "PathNotFound": "指定的目录不存在!", "FilePathNotFound": "文件或目录不存在!", diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs index 634eba10e..b0303b976 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs @@ -1,93 +1,96 @@ -using LINGYUN.Abp.OssManagement.Permissions; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Threading.Tasks; -using System.Web; -using Volo.Abp; -using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.Http; -using Volo.Abp.Validation; - -namespace LINGYUN.Abp.OssManagement -{ - [RemoteService(Name = OssManagementRemoteServiceConsts.RemoteServiceName)] - [Area("oss-management")] - [Route("api/files/static")] - public class StaticFilesController : AbpController - { - private readonly IOssObjectAppService _ossObjectAppService; - private readonly IStaticFilesAppService _staticFilesAppServic; - - public StaticFilesController( - IOssObjectAppService ossObjectAppService, - IStaticFilesAppService staticFilesAppServic) - { - _ossObjectAppService = ossObjectAppService; - _staticFilesAppServic = staticFilesAppServic; - } - - [HttpPost] - [Route("{bucket}")] - [Route("{bucket}/p/{path}")] - [Route("{bucket}/p/{path}/{name}")] - [Authorize(AbpOssManagementPermissions.OssObject.Create)] - public virtual async Task UploadAsync(string bucket, string path, string name, [FromForm] IFormFile file) - { - if (file == null || file.Length <= 0) - { - ThrowValidationException(L["FileNotBeNullOrEmpty"], "File"); - } - - var createOssObjectInput = new CreateOssObjectInput - { - Bucket = HttpUtility.UrlDecode(bucket), - Path = HttpUtility.UrlDecode(path), - Object = name ?? file.FileName, - Content = file.OpenReadStream(), - Overwrite = true - }; - - return await _ossObjectAppService.CreateAsync(createOssObjectInput); - } - - [HttpGet] - [Route("{bucket}/{name}")] - [Route("{bucket}/{name}/{process}")] - [Route("{bucket}/p/{path}/{name}")] - [Route("{bucket}/p/{path}/{name}/{process}")] - public virtual async Task GetAsync(string bucket, string path, string name, string process) - { - var input = new GetStaticFileInput - { - Bucket = bucket, - Name = name, - Path = path, - Process = process - }; - var fileStream = await _staticFilesAppServic.GetAsync(input); - - if (fileStream.IsNullOrEmpty()) - { - return NotFound(); - } - - return File( - fileStream, - MimeTypes.GetByExtension(Path.GetExtension(input.Name)) - ); - } - - private static void ThrowValidationException(string message, string memberName) - { - throw new AbpValidationException(message, - new List - { - new ValidationResult(message, new[] {memberName}) - }); - } - } -} +using LINGYUN.Abp.OssManagement.Localization; +using LINGYUN.Abp.OssManagement.Permissions; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Threading.Tasks; +using System.Web; +using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Http; +using Volo.Abp.Validation; + +namespace LINGYUN.Abp.OssManagement +{ + [RemoteService(Name = OssManagementRemoteServiceConsts.RemoteServiceName)] + [Area("oss-management")] + [Route("api/files/static")] + public class StaticFilesController : AbpController + { + private readonly IOssObjectAppService _ossObjectAppService; + private readonly IStaticFilesAppService _staticFilesAppServic; + + public StaticFilesController( + IOssObjectAppService ossObjectAppService, + IStaticFilesAppService staticFilesAppServic) + { + _ossObjectAppService = ossObjectAppService; + _staticFilesAppServic = staticFilesAppServic; + + LocalizationResource = typeof(AbpOssManagementResource); + } + + [HttpPost] + [Route("{bucket}")] + [Route("{bucket}/p/{path}")] + [Route("{bucket}/p/{path}/{name}")] + [Authorize(AbpOssManagementPermissions.OssObject.Create)] + public virtual async Task UploadAsync(string bucket, string path, string name) + { + if (Request.ContentLength <= 0) + { + ThrowValidationException(L["FileNotBeNullOrEmpty"], "File"); + } + + var createOssObjectInput = new CreateOssObjectInput + { + Bucket = HttpUtility.UrlDecode(bucket), + Path = HttpUtility.UrlDecode(path), + Object = name ?? Request.Form.Files[0].FileName, + Content = Request.Form.Files[0].OpenReadStream(), + Overwrite = true + }; + + return await _ossObjectAppService.CreateAsync(createOssObjectInput); + } + + [HttpGet] + [Route("{bucket}/{name}")] + [Route("{bucket}/{name}/{process}")] + [Route("{bucket}/p/{path}/{name}")] + [Route("{bucket}/p/{path}/{name}/{process}")] + public virtual async Task GetAsync(string bucket, string path, string name, string process) + { + var input = new GetStaticFileInput + { + Bucket = bucket, + Name = name, + Path = path, + Process = process + }; + var fileStream = await _staticFilesAppServic.GetAsync(input); + + if (fileStream.IsNullOrEmpty()) + { + return NotFound(); + } + + return File( + fileStream, + MimeTypes.GetByExtension(Path.GetExtension(input.Name)) + ); + } + + private static void ThrowValidationException(string message, string memberName) + { + throw new AbpValidationException(message, + new List + { + new ValidationResult(message, new[] {memberName}) + }); + } + } +} diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/Properties/launchSettings.json b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/Properties/launchSettings.json index fc9124c2a..a03733d45 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/Properties/launchSettings.json +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/Properties/launchSettings.json @@ -1,20 +1,20 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:64238", - "sslPort": 0 - } - }, - "profiles": { - "LINGYUN.Platform.HttpApi.Host": { - "commandName": "Project", - "launchBrowser": false, - "applicationUrl": "http://localhost:30025", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:64238", + "sslPort": 0 + } + }, + "profiles": { + "LINGYUN.Platform.HttpApi.Host": { + "commandName": "Project", + "launchBrowser": false, + "applicationUrl": "http://localhost:30025", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +}