Closed benny-adiwijaya closed 2 years ago
Hi @benny-adiwijaya , set a custom collection of files to the ConnectorCommand.Files property should be fine. You can overwrite the IFormFileWrapper or create one. please take a look into the source code to see how it works.
Hi @trannamtrung1st, I was not successful to set a custom collection of files. Can you give little sample how to do it?
This is not built-in but you can try the below code. It may be changed in the future, so be careful since this is not supported in elFinder specs.
[Route("connector")]
public async Task<IActionResult> Connector()
{
await SetupConnectorAsync();
var cmd = ConnectorHelper.ParseCommand(Request);
var ccTokenSource = ConnectorHelper.RegisterCcTokenSource(HttpContext);
if (cmd.Cmd == ConnectorCommand.Cmd_Upload)
{
// Case 1: for chunking upload
if (cmd.Args.TryGetValue(ConnectorCommand.Param_Chunk, out var chunk) && chunk.ToString().Length > 0)
{
var isChunkMerge = !cmd.Args.TryGetValue(ConnectorCommand.Param_Cid, out var cid) || cid.ToString().Length == 0;
if (isChunkMerge)
{
var overrideForm = new Dictionary<string, StringValues>(cmd.Form);
overrideForm[ConnectorCommand.Param_Upload] = Guid.NewGuid().ToString();
cmd.Form = overrideForm;
}
}
else
{
// Case 2: for non-chunking upload
cmd.Files = cmd.Files?.Select(f =>
new FormFileWrapper(f.OpenReadStream(), f.Length, f.Name, Guid.NewGuid().ToString())); // custom name here
}
}
var conResult = await _connector.ProcessAsync(cmd, ccTokenSource);
var actionResult = conResult.ToActionResult(HttpContext);
return actionResult;
}
Nice, it works. Thank you
Hi, is it posible to customize uploadingFileName without overriding UploadAsync, so the server can control file name that uploaded by user?