Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create ShareFileClient without specifying it's size to be able to stream data to it?

I would like to create new blob on FileShareClient in Azure FileShare resource with .NET api. I cannot specify it's size in the beginning (because it will be filled with data later eg. csv file filled with lines, up to couple of GBs).

I was trying to use something like this in my code:

using Azure.Storage.Files.Shares

  ShareFileClient fileShare = new ShareFileClient(
            "MYConnectionString",
            "FileShareName",
            "TestDirectoryName");
  if (!fileShare.Exists())
        {
            fileShare.Create(0);
        }
var stream = fileShare.OpenWrite(true, 0);

[Edit] I have got an exception: System.ArgumentException: 'options.MaxSize must be set if overwrite is set to true' Is there any way to avoid specyfining this size?

like image 507
Jack n J Avatar asked Oct 30 '25 12:10

Jack n J


1 Answers

Please try to use the latest package Azure.Storage.Files.Shares, version 12.5.0.

Note, in the code new ShareFileClient(), the last parameter is the directory name + file name.

see the code below:

        ShareFileClient f2 = new ShareFileClient(connectionString, shareName, dirName + "/test.txt");
        if (!f2.Exists())
        {
            f2.Create(0);
        }

The file with 0 size can be created, here is the test result:

enter image description here

like image 195
Ivan Yang Avatar answered Nov 01 '25 00:11

Ivan Yang