Skip to content

Commit

Permalink
Merge pull request #37 from sivakumars3442/master
Browse files Browse the repository at this point in the history
902938: Provided Chunk upload support for File Manager component.
  • Loading branch information
keerthanaRajendran authored Sep 27, 2024
2 parents 1676665 + 0e26bec commit 9a0e245
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Controllers/FileManagerAccessController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public object FileOperations([FromBody] FileManagerDirectoryContent args)

// uploads the file(s) into a specified path
[Route("Upload")]
public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action)
public IActionResult Upload(string path, long size, IList<IFormFile> uploadFiles, string action)
{
try
{
Expand All @@ -98,7 +98,7 @@ public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string ac
}
}
}
uploadResponse = operation.Upload(path, uploadFiles, action, null);
uploadResponse = operation.Upload(path, uploadFiles, action, size, null);
if (uploadResponse.Error != null)
{
Response.Clear();
Expand Down
5 changes: 3 additions & 2 deletions Controllers/FileManagerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public object FileOperations([FromBody] FileManagerDirectoryContent args)

// uploads the file(s) into a specified path
[Route("Upload")]
public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action)
[DisableRequestSizeLimit]
public IActionResult Upload(string path, long size, IList<IFormFile> uploadFiles, string action)
{
try
{
Expand All @@ -97,7 +98,7 @@ public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string ac
}
}
}
uploadResponse = operation.Upload(path, uploadFiles, action, null);
uploadResponse = operation.Upload(path, uploadFiles, action, size, null);
if (uploadResponse.Error != null)
{
Response.Clear();
Expand Down
4 changes: 2 additions & 2 deletions Controllers/VirtualizationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public object FileOperations([FromBody] FileManagerDirectoryContent args)

// uploads the file(s) into a specified path
[Route("Upload")]
public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action)
public IActionResult Upload(string path, long size, IList<IFormFile> uploadFiles, string action)
{
try
{
Expand All @@ -97,7 +97,7 @@ public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string ac
}
}
}
uploadResponse = operation.Upload(path, uploadFiles, action, null);
uploadResponse = operation.Upload(path, uploadFiles, action, size, null);
if (uploadResponse.Error != null)
{
Response.Clear();
Expand Down
2 changes: 1 addition & 1 deletion Models/Base/FileProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface FileProviderBase
#if EJ2_DNX
FileManagerResponse Upload(string path, IList<System.Web.HttpPostedFileBase> uploadFiles, string action, params FileManagerDirectoryContent[] data);
#else
FileManagerResponse Upload(string path, IList<IFormFile> uploadFiles, string action, params FileManagerDirectoryContent[] data);
FileManagerResponse Upload(string path, IList<IFormFile> uploadFiles, string action, long size, params FileManagerDirectoryContent[] data);
#endif

FileStreamResult GetImage(string path, string id, bool allowCompress, ImageSize size, params FileManagerDirectoryContent[] data);
Expand Down
46 changes: 29 additions & 17 deletions Models/PhysicalFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ protected virtual ImageSize FindRatio(ImageSize originalSize, ImageSize targetSi
#if EJ2_DNX
public virtual FileManagerResponse Upload(string path, IList<System.Web.HttpPostedFileBase> uploadFiles, string action, params FileManagerDirectoryContent[] data)
#else
public virtual FileManagerResponse Upload(string path, IList<IFormFile> uploadFiles, string action, params FileManagerDirectoryContent[] data)
public virtual FileManagerResponse Upload(string path, IList<IFormFile> uploadFiles, string action, long size, params FileManagerDirectoryContent[] data)
#endif
{
FileManagerResponse uploadResponse = new FileManagerResponse();
Expand Down Expand Up @@ -1317,16 +1317,14 @@ public virtual FileManagerResponse Upload(string path, IList<IFormFile> uploadFi
throw new UnauthorizedAccessException("Access denied for Directory-traversal");
}
#endif
long fileLength = File.Exists(fullName) ? new FileInfo(fullName).Length : default;
if (action == "save")
{
if (!System.IO.File.Exists(fullName))
bool isValidChunkUpload = file.ContentType == "application/octet-stream" && (fileLength != size);
if (!System.IO.File.Exists(fullName) || isValidChunkUpload)
{
#if !EJ2_DNX
using (FileStream fs = System.IO.File.Create(fullName))
{
file.CopyTo(fs);
fs.Flush();
}
PerformUpload(file, fileLength, size, fullName);
#else
file.SaveAs(fullName);
#endif
Expand Down Expand Up @@ -1357,11 +1355,7 @@ public virtual FileManagerResponse Upload(string path, IList<IFormFile> uploadFi
System.IO.File.Delete(fullName);
}
#if !EJ2_DNX
using (FileStream fs = System.IO.File.Create(fullName))
{
file.CopyTo(fs);
fs.Flush();
}
PerformUpload(file, fileLength, size, fullName);
#else
file.SaveAs(fullName);
#endif
Expand All @@ -1379,11 +1373,8 @@ public virtual FileManagerResponse Upload(string path, IList<IFormFile> uploadFi
}
newName = newName + (fileCount > 0 ? "(" + fileCount.ToString() + ")" : "") + Path.GetExtension(name);
#if !EJ2_DNX
using (FileStream fs = System.IO.File.Create(newName))
{
file.CopyTo(fs);
fs.Flush();
}
long newFileLength = File.Exists(newName) ? new FileInfo(newName).Length : default;
PerformUpload(file, newFileLength, size, newName);
#else
file.SaveAs(newName);
#endif
Expand Down Expand Up @@ -1411,6 +1402,27 @@ public virtual FileManagerResponse Upload(string path, IList<IFormFile> uploadFi
return uploadResponse;
}
}

private void PerformUpload(IFormFile file, long fileLength, long size, string name)
{
bool isValidChunkUpload = file.ContentType == "application/octet-stream" && (fileLength != size);

if (file.ContentType == "application/octet-stream")
{
using (var fileStream = new FileStream(name, FileMode.Append))
{
file.CopyTo(fileStream);
}
}
else
{
using (FileStream fs = System.IO.File.Create(name))
{
file.CopyTo(fs);
fs.Flush();
}
}
}
#if SyncfusionFramework4_0
public virtual void Download(string path, string[] names, params FileManagerDirectoryContent[] data)
{
Expand Down

0 comments on commit 9a0e245

Please sign in to comment.