ChunkSize Create problem while uploading video

1) Using Syncfusion file upload I am uploading videos into my WWWROOT FOLDER PATH.


allowedExtensions=".mp4" asyncSettings="@asyncSettingsVideo" directoryUpload="true" success="onSuccess" maxFileSize="268435456" >

var asyncSettingsVideo = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = @Url.Content("~/CONTROLLER_NAME /SaveVideo/"), RemoveUrl = @Url.Content("~/CONTROLLER_NAME/RemoveVideo"), ChunkSize = 500000 };

public void SaveVideo(IListchunkFile, IListformFileVideo)
{
....
var uploaderFilePath = hostingEnv.WebRootPath + "\\UploadVideos\\";
}

2) Now next step is FROM WWWROOT FOLDER I AM GETTING THE PATH OF THE VIDEO and uploading the VIDEO FILES into Azure BLOB Storage.

FOR ONE OF MY VIDEO, Here ORIGINAL SIZE OF THE VIDEO IS:- 220608443


int blocksize = 4;
long bytesCopiedForAllFiles = 0;
byte[] buffer = new byte[16 * 1024];
long bytesToUpload = (new FileInfo(fileToUpload)).Length;

BUT WHEN CHECK THE IF CONDITION, the value of bytesToUpload shows me 500000.

if (bytesToUpload < blocksize * 1024 * 1024) {

}
else
{
....

var bytesToRead = Math.Min(blocksize * 1024 * 1024, bytesToUpload);
var blobContents = new byte[bytesToRead];
.....
var blockAsync = blob.PutBlockAsync(blockId, new MemoryStream(blobContents), null);
}

I want to keep the SIZE AS IT IS THE ORIGINAL ONE, So MY ELSE CONDITION WILL FIRE AND I CAN UPLOAD MY VIDEO INTO AZURE.


5 Replies 1 reply marked as answer

SP Sureshkumar P Syncfusion Team March 30, 2022 12:57 PM UTC

Hi Veet,

The default allowed maximum request in kilobytes size is 4096 KB (4 MB). If you want to increase the size, you need to update your application

Please set the maximum requirement file size limit in the controls as well in the startup configuration to achieve your requirement.


[cshtml]

<ejs-uploader id="UploadFileSource" removing="onFileRemove" asyncSettings="@asyncSettings" maxFileSize="5000000000" autoUpload="false" multiple="false" ></ejs-uploader>


[startup.cs]

        public void ConfigureServices(IServiceCollection services)

        {

            services.AddMvc();

            services.Configure<FormOptions>(o => {

                o.ValueLengthLimit = int.MaxValue;

                o.MultipartBodyLengthLimit = 5000000000;

                o.MemoryBufferThreshold = int.MaxValue;

            });

 

        }


[controller]

        [AcceptVerbs("Post")]

        [DisableRequestSizeLimit]

        public IActionResult Save(IList<IFormFile> UploadFileSource, IList<IFormFile> UploadFilesTarget)

        {


Regards,

Sureshkumar P.



VE Veet March 31, 2022 06:11 AM UTC

Hello

Sureshkumar P,

Still facing the same issue. Please understand my requirements. Using syncfusion FILE Upload first I am Uploading my video into the wwwroot. And then after when I click on the dialog box (YES/NO) at that time I am uploading my video FROM WWWROOT FOLDER to AZURE BLOB. Please check my exact code as I have specified down below.


1) asynSettingCode

@{
var asyncSettingsVideo = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = @Url.Content("~/CONTROLLER_NAME/SaveVideo/"), RemoveUrl = @Url.Content("~/CONTROLLER_NAME/RemoveVideo"), ChunkSize = 500000 };
}

2) File Upload Code

  allowedExtensions=".mp4"  asyncSettings="@asyncSettingsVideo" directoryUpload="true" maxFileSize="5000000000" success="onSuccess">


3) My Controller Side code

[AcceptVerbs("Post")]
[DisableRequestSizeLimit]
public void SaveVideo(IList chunkFile, IList formFileVideo)
{


long size = 0;
try
{
foreach (var file in formFileVideo)
{
var filename = ContentDispositionHeaderValue
.Parse(file.ContentDisposition)
.FileName
.Trim('"');
var folders = filename.Split('/');
var uploaderFilePath = hostingEnv.WebRootPath;
// for Directory upload
if (folders.Length > 1)
{
for (var i = 0; i < folders.Length - 1; i++)
{
var newFolder = uploaderFilePath + $@"\{folders[i]}";
Directory.CreateDirectory(newFolder);
uploaderFilePath = newFolder;
filename = folders[i + 1];
}
}


filename = uploaderFilePath + $@"\{filename}";
size += file.Length;
if (!System.IO.File.Exists(filename))
{
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}


}
}
}
catch (Exception e)
{
Response.Clear();
Response.StatusCode = 204;
Response.HttpContext.Features.Get().ReasonPhrase = "File failed to upload";
Response.HttpContext.Features.Get().ReasonPhrase = e.Message;
}
}

4) Now I have a button When I click on it then THE UPLOADING PROCESS IN AZURE GETS STARTED

BUT INSTEAD OF TAKING THE ORIGINAL SIZE IT ( ORIGINAL SIZE OF THE VIDEO IS- 220608443 ) SHOWS ME bytesToUpload shows me 500000.



5) DIALOG BOX CONFIRM BOX (YES/NO)

 document.getElementById("dialogBtn").onclick = function () {


ej.popups.DialogUtility.confirm({
title: ' Confirmation Dialog',
content: "Admin ! Are you to upload video in AZURE BLOB!",
okButton: {
text: 'OK', click: function () {
okUpload();
this.hide();
} },
cancelButton: { text: 'Cancel', click: function () {
cancelClickTest();
this.hide();
} },
showCloseIcon: true,
closeOnEscape: true,
animationSettings: { effect: 'Zoom' }
});


};

6) Function Code

function okUpload () {
$.ajax({
url: "@Url.Action("FUNCTION_NAME", "CONTROLLER_NAME")",
data: JSON.stringify(MY_Data),
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
location.reload();
},
error: function (data) {
}
});
}

7) HERE in controller side THE UPLOADING PROCESS START

if (bytesToUpload < blocksize * 1024 * 1024) {

}
else
{
....

var bytesToRead = Math.Min(blocksize * 1024 * 1024, bytesToUpload);
var blobContents = new byte[bytesToRead];
.....
var blockAsync = blob.PutBlockAsync(blockId, new MemoryStream(blobContents), null);
}

VIDEO_SIZE.png

STILL, IT TAKES THE 50000.


MOST IMP in MY PROJECT THE MINIMUM SIZE OF VIDEO IS 2GB and MAXIMUM SIZE OF VIDEO is 9GB. THIS IS FIXED FROM THE CLIENT'S SIDE. 


ACCORDING TO THAT PLEASE HELP ME to ADJUST THE CHUNK SIZE. 

I AM INTERESTED TO SET THE CHUNKSIZE AS 

var asyncSettingsVideo = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = @Url.Content("~/CONTROLLER_NAME/SaveVideo/"), RemoveUrl = @Url.Content("~/CONTROLLER_NAME/RemoveVideo"), ChunkSize = 2000000000 };

BUT SHOWS ME FAILED.  //CHUNK SIZE MUST BE 2000000000


SP Sureshkumar P Syncfusion Team March 31, 2022 06:46 AM UTC

Hi Veet,


Query 1: Using syncfusion FILE Upload first I am Uploading my video into the wwwroot. And then after when I click on the dialog box (YES/NO) at that time I am uploading my video FROM WWWROOT FOLDER to AZURE BLOB. Please check my exact code as I have specified down below.


We suspect that you have uploaded the file to Azure blob before the chunk upload completed. Which is the scenario the file size displays in the provided chunk size.


Also, we suggest you upload the file directly to the azure blob storage by using our uploader component.


Find the code example here:

[index.cshtml]

 

@{

    var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "/Home/Save", RemoveUrl = "/Home/Remove", ChunkSize = 102400 };

}

<ejs-uploader id="uploadFiles" asyncSettings="@asyncSettings" autoUpload="false"></ejs-uploader>

 

[home.controller.cs]

 

public async Task Save(IList<IFormFile> chunkFile, IList<IFormFile> uploadFiles)

        {

            try

 

            {

 

                foreach (var file in chunkFile)

 

                {

 

                    var httpPostedChunkFile = HttpContext.Request.Form.Files["chunkFile"];

 

                    var chunkIndex = HttpContext.Request.Form["chunk-index"];

 

                    var totalChunk = HttpContext.Request.Form["total-chunk"];

 

                    using (var fileStream = file.OpenReadStream())

 

                    {

 

                        if (Convert.ToInt32(chunkIndex) <= Convert.ToInt32(totalChunk))

 

                        {

 

                            var streamReader = new MemoryStream();

 

                            fileStream.CopyTo(streamReader);

 

                            var byteArr = streamReader.ToArray();

 

                            if (content.Length > 0)

                            {

                                content = content.Concat(byteArr).ToArray();

                            }

                            else

                            {

                                content = byteArr;

                            }

 

                        }

 

                        if (Convert.ToInt32(chunkIndex) == Convert.ToInt32(totalChunk) - 1)

 

                        {

                            const string accountName = "*************"; // Provide the account name

                            const string key = "**********************"; // Provide the account key

 

                            var storageCredentials = new StorageCredentials(accountName, key);

 

                            var cloudStorageAccount = new CloudStorageAccount(storageCredentials, true);

 

                            var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();

 

                            var container = cloudBlobClient.GetContainerReference("filo");

 

                            CloudBlockBlob blockBlob = container.GetBlockBlobReference(httpPostedChunkFile.FileName);

 

                            using (FileStream fileStreams = new FileStream(httpPostedChunkFile.FileName, FileMode.Create))

 

                            {

 

                                for (int i = 0; i < content.Length; i++)

 

                                {

 

                                    fileStreams.WriteByte(content[i]);

 

                                }

 

                                fileStreams.Seek(0, SeekOrigin.Begin);

 

                                content = new byte[] { };

 

                                await blockBlob.UploadFromStreamAsync(fileStreams);

 

                            }

 

                        }

 

                    }

 

                }

 

            }

 

            catch (Exception e)

 

            {

                content = new byte[] { };

                Response.Clear();

                Response.StatusCode = 204;

                Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File failed to upload";

                Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;

 

            }

        }


We have created the sample based on your scenario. Please find the sample in the attachment.



Query 2: MOST IMP in MY PROJECT THE MINIMUM SIZE OF VIDEO IS 2GB and MAXIMUM SIZE OF VIDEO is 9GB. THIS IS FIXED FROM THE CLIENT'S SIDE.

ACCORDING TO THAT PLEASE HELP ME to ADJUST THE CHUNK SIZE.

I AM INTERESTED TO SET THE CHUNKSIZE AS


You can increase the chunksize as you wanted but same time you need to increase the maxFileSize property value as in the previous update.


Regards,

Sureshkumar P


Attachment: Uploader_983e16fd.zip

Marked as answer

VE Veet April 1, 2022 11:55 AM UTC

Thank you very much it is working now. If any further changes then let you know. 



SP Sureshkumar P Syncfusion Team April 4, 2022 07:20 AM UTC

Veet,


Thanks for your update.


Regards,

Sureshkumar P


Loader.
Up arrow icon