GithubHelp home page GithubHelp logo

easyabp / filemanagement Goto Github PK

View Code? Open in Web Editor NEW
95.0 5.0 38.0 6.91 MB

An abp.io application module that allows users to upload and maintain files.

License: MIT License

C# 95.98% Dockerfile 0.33% HTML 2.09% JavaScript 1.44% CSS 0.16%

filemanagement's Introduction

FileManagement

ABP version NuGet NuGet Download Discord online GitHub stars

An abp.io application module that allows users to upload and maintain files.

Installation

  1. Install the following NuGet packages. (see how)

    • EasyAbp.FileManagement.Application
    • EasyAbp.FileManagement.Application.Contracts
    • EasyAbp.FileManagement.Domain
    • EasyAbp.FileManagement.Domain.Shared
    • EasyAbp.FileManagement.EntityFrameworkCore
    • EasyAbp.FileManagement.HttpApi
    • EasyAbp.FileManagement.HttpApi.Client
    • (Optional) EasyAbp.FileManagement.MongoDB
    • (Optional) EasyAbp.FileManagement.Web
  2. Add DependsOn(typeof(FileManagementXxxModule)) attribute to configure the module dependencies. (see how)

  3. Add builder.ConfigureFileManagement(); to the OnModelCreating() method in MyProjectMigrationsDbContext.cs.

  4. Add EF Core migrations and update your database. See: ABP document.

Usage

  1. Add permissions to the roles you want.

  2. Configure a BLOB container. (see sample and doc)

  3. Configure a file container. (see sample)

  4. Create a custom FileOperationAuthorizationHandler. (see sample)

  5. Create a file manager page. (see sample)

  6. Add a menu item for the file manager page. (see sample)

Files Upload

Road map

  • Multi container.
  • Multi file upload.
  • Upload constraints.
  • User-space isolation.
  • Reuse existing BLOB resources.
  • Directory occupancy statistics.
  • Auto deleting unused BLOB resources.
  • Auto rename files with duplicate names.
  • Container space quota control.
  • Customized upload way.
  • Complex file search.
  • Unit tests.

filemanagement's People

Contributors

gdlcf88 avatar hueifeng avatar jadynwong avatar shiflowa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

filemanagement's Issues

How to replace `BasicFileOperationAuthorizationHandler`?

自定义了文件上传权限检查并且通过,但是结果还是授权失败,查看源码,是由于BasicFileOperationAuthorizationHandler中检查了权限,由于我们定义的是所有用户都可以上传文件,包含未登陆用户,用什么方法可以阻止BasicFileOperationAuthorizationHandler中的权限检查呢

Bread crumb on the file list page

After #17, the FilePath property is moved.

  • We should consider how to get and current directory path and show it as the bread crumb on the file list page.
  • Each node of the bread crumb could be clicked and redirect to the page of the node.

授权失败

你好!开了权限的,操作时还是提示授权失败!1.3.1和1.3.3的版本也会提示。提示如附图
image

Reuse existing BLOBs and auto delete unused BLOBs

  • If a file is uploaded a second time, find the existing BLOB and reuse it.
  • BLOB's auto-deleting feature: When updating the content of a file or deleting a file, create a new BLOB and remove the old BLOB.
  • There should be an option to control the BLOB's auto-deleting feature.

File name length and unique constraints

This is a breaking change.

  1. The file names are limited to 255 chars.

  2. A new unique index is added to ensure consistency.

builder.Entity<File>(b =>
{
    // ...
    b.HasIndex(x => new { x.FileName, x.ParentId, x.OwnerUserId, x.FileContainerName }).IsUnique();
});

找不到远端方法

当启动了 IdengityServer HttpApi.Host Web.Host
WebHost加载列表页发生错误,包括上传文件等按钮点击都报错了
错误信息:

Could not found remote action for method: System.Threading.Tasks.Task`1[EasyAbp.Abp.FileManagement.Containers.PublicFileContainerConfiguration] GetConfigurationAsync(System.String, System.Nullable`1[System.Guid]) on the URL: https://localhost:44313/

这个会不会是因为FileController没有继承自IFileAppService的原因呢,因为没有i继承自IFileAppService,所以在FileManagement.Web层调用IFileAppservice的相关的接口的时候,其实是没有找到其对应的实现,在Web.Host层引用HttpApi.Client层的时候,没有生成远端对应的IFileAppService相关的接口。
这些纯属个人理解,对abp原理理解的还不够深入,有不对的地方劳烦帮忙解惑。

Behavior restricting feature

  • Size limit for each file. (for each container)
  • Total size limit for each upload. (for each container)
  • Allowed and disabled file extensions. (for each container)
  • Total capacity of a container.

Questions about DownloadAsync

public virtual async Task<FileDownloadOutput> DownloadAsync(Guid id, string token)
{
var provider = LazyServiceProvider.LazyGetRequiredService<ILocalFileDownloadProvider>();
await provider.CheckTokenAsync(token, id);
var file = await GetEntityByIdAsync(id);
return new FileDownloadOutput
{
FileName = file.FileName,
MimeType = file.MimeType,
Content = await provider.GetDownloadBytesAsync(file)
};
}

Why not consider using the token directly to get the resource ID.

Replace Task CheckTokenAsync(token, id) with Task<Guid> GetResourceIdByToken(token)

public virtual async Task CheckTokenAsync(string token, Guid fileId)

Count SubFilesQuantity and ByteSize of directory

  • The ByteSize of a directory file is the total byte size of all its subfiles (including the subdirectories).
  • When the ParentId or the ByteSize of a file is changed, should try to add a SubFileUpdatedEto local domain event to both the file's old and new parent file.
  • Should handle the SubFileUpdatedEto local event and recount the SubFilesQuantity and the ByteSize.

File flag

  • Add a string type property named Flag with the null value by default to the File entity.
  • Create a FlagFileEto and handler it in distributed event bus to set the flag property of the specified file.

For example, users may upload some images but never use them, so we can flag the files that are used, and regularly cleaning the unused files (with null flag value).

FileManager widget

Different file containers have different authorization requirements. Due to the complex logic for file operations authorization implemented in our backend AuthorizationHandlers, the frontend UI does not have clear visibility into whether a user has permission or not. As a result, the UI always displays the options. For example, even if a user doesn't have permission to upload files in the "Archive" directory, the UI will still show the "Upload" button.

To address this problem, we will encapsulate the file manager UI into an ABP MVC widget (https://docs.abp.io/en/abp/latest/UI/AspNetCore/Widgets), allowing for reusability and customization in application development. This approach is also more conducive to providing different UI entry points for different file containers.

The file management web module not work with EasyAbp.Abp.TagHelperPlus 1.5.0

The exception message shows:
An unhandled exception has occurred while executing the request.
System.MissingMethodException: Method not found: 'Void EasyAbp.Abp.TagHelperPlus.EasySelector.EasySelectorAttribute..ctor(System.String, System.String, System.String, System.String, System.String, System.String, System.String, Int32, Boolean, Boolean)'.

I checked the code of EasySelectorAttribute, seemingly the constructor of EasySelectorAttribute add new param from 1.4.1 version.
image
but the view model missing it.
image

升级到1.6.0出错

Volo.Abp.AbpInitializationException: An error occurred during ConfigureServices phase of the module EasyAbp.FileManagement.EntityFrameworkCore.FileManagementEntityFrameworkCoreModule, EasyAbp.FileManagement.EntityFrameworkCore, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null. See the inner exception for details.
---> System.TypeLoadException: Method 'GetEnumerator' in type 'EasyAbp.FileManagement.Files.FileRepository' from assembly 'EasyAbp.FileManagement.EntityFrameworkCore, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
at EasyAbp.FileManagement.EntityFrameworkCore.FileManagementEntityFrameworkCoreModule.<>c.b__0_0(IAbpDbContextRegistrationOptionsBuilder options)
at Microsoft.Extensions.DependencyInjection.AbpEfCoreServiceCollectionExtensions.AddAbpDbContext[TDbContext](IServiceCollection services, Action1 optionsBuilder) at EasyAbp.FileManagement.EntityFrameworkCore.FileManagementEntityFrameworkCoreModule.ConfigureServices(ServiceConfigurationContext context) at Volo.Abp.AbpApplicationBase.ConfigureServices() --- End of inner exception stack trace --- at Volo.Abp.AbpApplicationBase.ConfigureServices() at Volo.Abp.AbpApplicationBase..ctor(Type startupModuleType, IServiceCollection services, Action1 optionsAction)
at Volo.Abp.AbpApplicationWithExternalServiceProvider..ctor(Type startupModuleType, IServiceCollection services, Action1 optionsAction) at Volo.Abp.AbpApplicationFactory.Create(Type startupModuleType, IServiceCollection services, Action1 optionsAction)
at Volo.Abp.AbpApplicationFactory.Create[TStartupModule](IServiceCollection services, Action1 optionsAction) at Microsoft.Extensions.DependencyInjection.ServiceCollectionApplicationExtensions.AddApplication[TStartupModule](IServiceCollection services, Action1 optionsAction)
at Samruo.OA.Web.Startup.ConfigureServices(IServiceCollection services) in D:\projects\OA\src\Samruo.OA.Web\Startup.cs:line 10
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Samruo.OA.Web.Program.Main(String[] args) in D:\projects\OA\src\Samruo.OA.Web\Program.cs:line 31

API报错

运行起来后测试API时报400错误,日志显示
[16:52:29 ERR] The required antiforgery cookie ".AspNetCore.Antiforgery.wFLV_IZKzC0" is not present.
请问这个该怎么样解决呢?谢谢!
IdentityServer已经运行的了。

abp升级到4.3.0出错

2021-04-25 09:11:18.090 +08:00 [FTL] Host terminated unexpectedly! System.TypeLoadException: Could not load type 'Volo.Abp.Authorization.Permissions.IPermissionChecker' from assembly 'Volo.Abp.Authorization, Version=4.3.0.0, Culture=neutral, PublicKeyToken=null'. at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType) at System.Reflection.RuntimeConstructorInfo.get_Signature() at System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy() at System.Reflection.RuntimeConstructorInfo.GetParameters() at Autofac.Core.Activators.Reflection.ConstructorBinder..ctor(ConstructorInfo constructorInfo) at Autofac.Core.Activators.Reflection.ReflectionActivator.ConfigurePipeline(IComponentRegistryServices componentRegistryServices, IResolvePipelineBuilder pipelineBuilder) at Autofac.Core.Registration.ComponentRegistration.BuildResolvePipeline(IComponentRegistryServices registryServices, IResolvePipelineBuilder pipelineBuilder) at Autofac.Core.Registration.ComponentRegistration.BuildResolvePipeline(IComponentRegistryServices registryServices) at Autofac.Core.Registration.ComponentRegistryBuilder.Build() at Autofac.ContainerBuilder.Build(ContainerBuildOptions options) at Volo.Abp.Autofac.AbpAutofacServiceProviderFactory.CreateServiceProvider(ContainerBuilder containerBuilder) at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter1.CreateServiceProvider(Object containerBuilder)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Samruo.Abp.Receive.Web.Program.Main(String[] args) in D:\projects\Receive\src\Samruo.Abp.Receive.Web\Program.cs:line 31`

Error creating directory,but the upload file function can work normally

[WRN] The type (Directory) of the file (a99dec3f-a51d-a1a7-2a47-39f6d0fbe5be) is unexpected, it should be RegularFile.
EasyAbp.FileManagement.Files.UnexpectedFileTypeException: The type (Directory) of the file (a99dec3f-a51d-a1a7-2a47-39f6d0fbe5be) is unexpected, it should be RegularFile.
at EasyAbp.FileManagement.Files.FileManager.GetDownloadInfoAsync(File file)
at EasyAbp.FileManagement.Files.FileAppService.CreateAsync(CreateFileInput input)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)

KRZ84`K)WOMH8J3K9~AV0A6

是否考虑url的token授权支持其它方式?

由于url中放置token认证,会导致资源下载每次url不唯一,前端是根据url来缓存资源的,这样缓存会持续失效下载重复资源
是否可以针对此问题,进行其它形式的鉴权?

Upgrade to match with ABP V 4.3

bugs on CreateDirectory

when click CreateDirectory,there is a wrong happen. I debug the code ,find when create directory,no needs to CheckFileExtension,
so I change the code in FileAppService.cs as follow:

  public override async Task<FileInfoDto> CreateAsync(CreateFileDto input)
        {
            var configuration = _configurationProvider.Get(input.FileContainerName);

            CheckFileSize(new Dictionary<string, long> {{input.FileName, input.Content?.LongLength ?? 0}}, configuration);
            if (input.FileType == FileType.RegularFile)//I change this
            {
                CheckFileExtension(new[] { Path.GetExtension(input.FileName) }, configuration);
            }
         
            var parent = await TryGetEntityByNullableIdAsync(input.ParentId);

            var file = await _fileManager.CreateAsync(input.FileContainerName, input.OwnerUserId, input.FileName,
                input.MimeType, input.FileType, parent, input.Content);

            await AuthorizationService.AuthorizeAsync(CreateFileOperationInfoModel(file),
                new OperationAuthorizationRequirement {Name = FileManagementPermissions.File.Create});
            
            await _repository.InsertAsync(file, autoSave: true);

            await _fileManager.TrySaveBlobAsync(file, input.Content);

            return MapToGetOutputDto(file);
        }

and it works. hope the next version will correct this. thank you for your good works

Instructions to add from Nuget

It is not very clear how to add this module from source or from nuget as someone new to the abp and easyabp platform. Some pointers would be helpful.

Added all from Nuget, no source:

  1. it is easy to add easyabp.filemanagement using the abphelper or abphelper.gui however it does not add the ui only the module. I completed this step without issue, created and ran the db migration and was able to see and add permissions to users.
  2. to add a ui, i added easyabp.filemanagement.blazor.server AND added [DependsOn(typeof(FileManagementBlazorServerModule) to the blazor server module. The "File" menu then showed up for users with permissions but the page is empty - message in the view instead says "Sorry, there's nothing at this address." and the address is "https://localhost:44371/FileManagement/Files/File". I believe that the blob storage needs to get setup?? However, it is not clear how to do this from the instructions in the github doc.

Any next steps for completing setup using only nuget package would be appreciated. Once this is working I would like to try from source but the instructions there are not clear for a newbie to abp.io framework. One thing at a time...

Use uppy.io

Use uppy.io to replace bootstrap-fileinput.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.