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: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!",

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:Upload": "上传",
"Permission:Download": "下载",
"FileNotBeNullOrEmpty": "上传文件不能为空!",
"FileNotFound": "指定的文件不存在!",
"PathNotFound": "指定的目录不存在!",
"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 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<OssObjectDto> 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<IActionResult> 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<ValidationResult>
{
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<OssObjectDto> 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<IActionResult> 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<ValidationResult>
{
new ValidationResult(message, new[] {memberName})
});
}
}
}

40
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"
}
}
}
}

Loading…
Cancel
Save