Browse Source

fix: removed IFormFile to StaticFilesController action

pull/297/head
cKey 4 years ago
parent
commit
b517f2c9d4
  1. 1
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json
  2. 1
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json
  3. 189
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs
  4. 40
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/Properties/launchSettings.json

1
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:Delete": "Delete",
"Permission:Upload": "Upload", "Permission:Upload": "Upload",
"Permission:Download": "Download", "Permission:Download": "Download",
"FileNotBeNullOrEmpty": "Upload file not be null!",
"FileNotFound": "The specified file does not exist!", "FileNotFound": "The specified file does not exist!",
"PathNotFound": "The specified directory does not exist!", "PathNotFound": "The specified directory does not exist!",
"FilePathNotFound": "The file or directory does not exist!", "FilePathNotFound": "The file or directory does not exist!",

1
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:Delete": "删除",
"Permission:Upload": "上传", "Permission:Upload": "上传",
"Permission:Download": "下载", "Permission:Download": "下载",
"FileNotBeNullOrEmpty": "上传文件不能为空!",
"FileNotFound": "指定的文件不存在!", "FileNotFound": "指定的文件不存在!",
"PathNotFound": "指定的目录不存在!", "PathNotFound": "指定的目录不存在!",
"FilePathNotFound": "文件或目录不存在!", "FilePathNotFound": "文件或目录不存在!",

189
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs

@ -1,93 +1,96 @@
using LINGYUN.Abp.OssManagement.Permissions; using LINGYUN.Abp.OssManagement.Localization;
using Microsoft.AspNetCore.Authorization; using LINGYUN.Abp.OssManagement.Permissions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http;
using System.Collections.Generic; using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations; using System.Collections.Generic;
using System.IO; using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.IO;
using System.Web; using System.Threading.Tasks;
using Volo.Abp; using System.Web;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp;
using Volo.Abp.Http; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Validation; using Volo.Abp.Http;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.OssManagement
{ namespace LINGYUN.Abp.OssManagement
[RemoteService(Name = OssManagementRemoteServiceConsts.RemoteServiceName)] {
[Area("oss-management")] [RemoteService(Name = OssManagementRemoteServiceConsts.RemoteServiceName)]
[Route("api/files/static")] [Area("oss-management")]
public class StaticFilesController : AbpController [Route("api/files/static")]
{ public class StaticFilesController : AbpController
private readonly IOssObjectAppService _ossObjectAppService; {
private readonly IStaticFilesAppService _staticFilesAppServic; private readonly IOssObjectAppService _ossObjectAppService;
private readonly IStaticFilesAppService _staticFilesAppServic;
public StaticFilesController(
IOssObjectAppService ossObjectAppService, public StaticFilesController(
IStaticFilesAppService staticFilesAppServic) IOssObjectAppService ossObjectAppService,
{ IStaticFilesAppService staticFilesAppServic)
_ossObjectAppService = ossObjectAppService; {
_staticFilesAppServic = staticFilesAppServic; _ossObjectAppService = ossObjectAppService;
} _staticFilesAppServic = staticFilesAppServic;
[HttpPost] LocalizationResource = typeof(AbpOssManagementResource);
[Route("{bucket}")] }
[Route("{bucket}/p/{path}")]
[Route("{bucket}/p/{path}/{name}")] [HttpPost]
[Authorize(AbpOssManagementPermissions.OssObject.Create)] [Route("{bucket}")]
public virtual async Task<OssObjectDto> UploadAsync(string bucket, string path, string name, [FromForm] IFormFile file) [Route("{bucket}/p/{path}")]
{ [Route("{bucket}/p/{path}/{name}")]
if (file == null || file.Length <= 0) [Authorize(AbpOssManagementPermissions.OssObject.Create)]
{ public virtual async Task<OssObjectDto> UploadAsync(string bucket, string path, string name)
ThrowValidationException(L["FileNotBeNullOrEmpty"], "File"); {
} if (Request.ContentLength <= 0)
{
var createOssObjectInput = new CreateOssObjectInput ThrowValidationException(L["FileNotBeNullOrEmpty"], "File");
{ }
Bucket = HttpUtility.UrlDecode(bucket),
Path = HttpUtility.UrlDecode(path), var createOssObjectInput = new CreateOssObjectInput
Object = name ?? file.FileName, {
Content = file.OpenReadStream(), Bucket = HttpUtility.UrlDecode(bucket),
Overwrite = true Path = HttpUtility.UrlDecode(path),
}; Object = name ?? Request.Form.Files[0].FileName,
Content = Request.Form.Files[0].OpenReadStream(),
return await _ossObjectAppService.CreateAsync(createOssObjectInput); Overwrite = true
} };
[HttpGet] return await _ossObjectAppService.CreateAsync(createOssObjectInput);
[Route("{bucket}/{name}")] }
[Route("{bucket}/{name}/{process}")]
[Route("{bucket}/p/{path}/{name}")] [HttpGet]
[Route("{bucket}/p/{path}/{name}/{process}")] [Route("{bucket}/{name}")]
public virtual async Task<IActionResult> GetAsync(string bucket, string path, string name, string process) [Route("{bucket}/{name}/{process}")]
{ [Route("{bucket}/p/{path}/{name}")]
var input = new GetStaticFileInput [Route("{bucket}/p/{path}/{name}/{process}")]
{ public virtual async Task<IActionResult> GetAsync(string bucket, string path, string name, string process)
Bucket = bucket, {
Name = name, var input = new GetStaticFileInput
Path = path, {
Process = process Bucket = bucket,
}; Name = name,
var fileStream = await _staticFilesAppServic.GetAsync(input); Path = path,
Process = process
if (fileStream.IsNullOrEmpty()) };
{ var fileStream = await _staticFilesAppServic.GetAsync(input);
return NotFound();
} if (fileStream.IsNullOrEmpty())
{
return File( return NotFound();
fileStream, }
MimeTypes.GetByExtension(Path.GetExtension(input.Name))
); return File(
} fileStream,
MimeTypes.GetByExtension(Path.GetExtension(input.Name))
private static void ThrowValidationException(string message, string memberName) );
{ }
throw new AbpValidationException(message,
new List<ValidationResult> private static void ThrowValidationException(string message, string memberName)
{ {
new ValidationResult(message, new[] {memberName}) throw new AbpValidationException(message,
}); new List<ValidationResult>
} {
} new ValidationResult(message, new[] {memberName})
} });
}
}
}

40
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/Properties/launchSettings.json

@ -1,20 +1,20 @@
{ {
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:64238", "applicationUrl": "http://localhost:64238",
"sslPort": 0 "sslPort": 0
} }
}, },
"profiles": { "profiles": {
"LINGYUN.Platform.HttpApi.Host": { "LINGYUN.Platform.HttpApi.Host": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": false, "launchBrowser": false,
"applicationUrl": "http://localhost:30025", "applicationUrl": "http://localhost:30025",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
} }
} }
} }

Loading…
Cancel
Save