Problem in uploading files more than 4 MB in WEB API FILE SHARE

Lalit Mathur 1 Reputation point
2021-03-10T07:23:14.893+00:00

We are not able to upload files >4MB below is the sample code. Please help.

UPLOADINg FILE of 7 MB to Azure File Share

UPLOADINg FILE of 7 MB to Azure File Share
Operation system : Linux
Client browser : Chrome
Azure Storage Type : File Share
Generation of SAS URL and creating empty file in file : Java
Uploading file using the SAS generated URL : Javascript

Sample Code

Backend code


//set policy
SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy();
policy.setPermissions(EnumSet.of(SharedAccessAccountPermissions.READ, SharedAccessAccountPermissions.WRITE, SharedAccessAccountPermissions.LIST,
SharedAccessAccountPermissions.DELETE, SharedAccessAccountPermissions.CREATE));
policy.setServices(EnumSet.of(SharedAccessAccountService.FILE));
policy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.OBJECT,SharedAccessAccountResourceType.SERVICE));
//policy.setSharedAccessExpiryTime(Date.from(ZonedDateTime.now(ZoneOffset.UTC).plusHours(24L).toInstant()));
policy.setSharedAccessExpiryTime(expiration);
policy.setProtocols(SharedAccessProtocols.HTTPS_ONLY);

//generate URL
String URL = endpoint+"/"+rootfoldername+"/"+storageDocumentPath+"?comp=range&"+azureaccount.generateSharedAccessSignature(policy)+"&sizeg="+fileSize;

//create a file
CloudFileDirectory dir = fetchRootDir("rootfoldername").getDirectoryReference(folderPath);
CloudFile file = dir.getFileReference(fileName);
file.create(fileSize);

front end code

while using the generated url from above to upload doing the header changes as below
options.headers['x-ms-write'] = "update";
options.headers['Range'] = "bytes=0-"+(file.size-1);
options.headers['x-ms-content-length'] = file.size;

we have tried with options.headers['x-ms-write'] = "clear";
But browser content-length can not make it zero
also but it does not work
Request Details Request URL: Request URL:

Request Details

Request URL: Request URL: https://<MYSHARENAME>.file.core.windows.net///?comp=range&ss=f&sig= SIGNATURE>&se=2021-03-09T16%3A39%3A15Z&sv=2015-07-08&srt=so&spr=https&sp=rcwdl&sr=so&sizeg=7905348
Request Method: PUT
Status Code: 413 The request body is too large and exceeds the maximum permissible limit.
Remote Address: <REMOTE ADDRESS>
Referrer Policy: strict-origin-when-cross-origin

Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: x-ms-request-id,Server,x-ms-version,Content-Length,Date,Transfer-Encoding
Content-Length: 288
Content-Type: application/xml
Date: Tue, 09 Mar 2021 06:38:43 GMT
Server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: b34481d2-401a-0053-2bae-143300000000
x-ms-version: 2015-07-08

Accept: application/xml, text/xml, /; q=0.01
Accept-Encoding: identity
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Disposition: attachment; filename="test.log"
Content-Length: 7905348
Content-Type: application/octet-stream
Host: <MYFILESAHRE>.file.core.windows.net
Origin: <MYDOMAIN>
Range: bytes=0-7905347
Referer: <MYDOMAIN>
sec-ch-ua: "Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36
x-ms-content-length: 7905348
x-ms-write: update

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,171 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sumarigo-MSFT 43,816 Reputation points Microsoft Employee
    2021-03-12T09:32:34.643+00:00

    @Lalit Mathur Thanks for raising this question! Firstly, apologies for the delay in responding here and any inconvenience this issue may have caused. Kindly try the following steps to isolate the issue:

    Just for testing purpose, can you try using Azcopy and let me know the status ?
    Can you re-verify the Source Location?
    There is a similar thread discussion in SO forum which may give some idea on your scenario.
    https://stackoverflow.com/questions/42277404/error-response-while-writing-file-more-than-4-mb-to-azure-fileshare-using-sas-ur

    There's a 4-MB limit for each call to the Azure Storage service. If your file is larger than 4 MB, you must break it in chunks. For more information, see Azure Storage scalability and performance targets.
    More than 4 megabytes (MB) of data to a file on Azure Storage, or you try to upload a file that's larger than 4 MB by using the SAS url (REST API) or HTTPS PUT method.

    If the issue still persists, please share the screenshot of the issue of the error message, I would like to work closer on this issue

    Hope this helps!

    Kindly let us know if the above helps or you need further assistance on this issue.

    ------------------------------------------------------------------------------------------------------------------------------

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


  2. Anonymous
    2021-10-18T17:33:33.873+00:00

    I figured out the issue. I am sending the whole file content in the body but I changed to read chunks of bytes and send it with each request and it worked like a charm.

    0 comments No comments