4 changed files with 118 additions and 113 deletions
@ -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}) |
||||
} |
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|||||
@ -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…
Reference in new issue