Open Closed

how to get the url of a file have uploaded to FileManager Module? #1715


User avatar
0
zsanhong created
  • ABP Framework version: v4.0
  • UI type:MVC
  • DB provider: EF Core
  • **Tiered (MVC)
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

I want to link to a file have uploaded to FileManager Module for example ,I have uploaded a file name "有害垃圾.docx" to FileManager

now In tui.Editor, I want insert a link when I click "Insert link" button

how to write the URL in the picture?


7 Answer(s)
  • User Avatar
    0
    cotur created

    Hi @zsanhong,

    Files that uploaded with File Management module can't be downloaded directly by a link for now. We've added "token validation" for extra security.

    First, the UI makes a request to the backend application to take token, that token will be used for download, Example:

    File name: myfile.zip UI makes a request -> // api/file-management/get-token Token = 12345 UI opens a new tab with the url -> api/file-management/[MY-FILE-ID]?token=12345 Then the download process will start.

    Tokens become expired when they used once. So, for each download request, you need to consume new token.

    So, how you can achieve your request, let me show you one example.

    You may create unique tokens for each dowload request by overriding DownloadAsync method of FileDescriptorController controller:

    Note that, you need to secure your api yourself.

    [HttpGet]
            [Route("download/{id}")]
            [AllowAnonymous]
            public virtual async Task<IRemoteStreamContent> DownloadAsync(Guid id, string token)
            {
                var fileDescriptor = await FileDescriptorAppService.GetAsync(id);
                
                // add this
                if(string.IsNullOrWhiteSpace(token))
                {
                    token = await FileDescriptorAppService.GetDownloadTokenAsync(id); 
                }
                
                Response.Headers.Add("Content-Disposition", $"attachment;filename=\"{fileDescriptor.Name}\"");
                Response.Headers.Add("Accept-Ranges", "bytes");
                Response.ContentType = fileDescriptor.MimeType;
    
                return await FileDescriptorAppService.DownloadAsync(id, token);
            }
    
  • User Avatar
    0
    zsanhong created

    thank you @cotur. for now, I can't get the Id of the file have uploaded to FileManager Module directly, So I want to add a CopyUrl method to achieve my request. thanks.

  • User Avatar
    0
    zsanhong created

    hi @cotur, how to overriding DownloadAsync method of FileDescriptorController controller? I don't want to change the source code of FileManager Module.

  • User Avatar
    0
    cotur created

    Here is the full documentation for it.

    https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Overriding-Services

  • User Avatar
    0
    zsanhong created

    thanks, another question. how to upload file size more than 28M? I can't upload file more than 28M in FileManagement Module

  • User Avatar
    0
    cotur created

    Hi,

    There is no any option about file sizes in ABP Framework or related modules.

    You may research for online. ABP Framework and File Management module use the default settings of ASP.NET.

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35