简体   繁体   中英

When I try to write on a file in Azure DataLake I get method not supported

I'm trying to whrite a file in the system, in azure but I get one error I can't figure out. The code works on my enviroment, but not on the zure.

I tried my code in different enviroments, they all work except for azure.

Below is my code.

    public async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        await _dlsService.Init();
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        log.LogInformation("Processing request: " + requestBody);
        CDTO cFile = JsonConvert.DeserializeObject<CDTO>(requestBody);

        string filePath = $"{cFile.DataLakeFolder}/{cFile.FileName}";
        var summary = _dlsService.GetMetadata(filePath);
        //string csvFileName = @"";

        try
        {
            string pathToFile = $"{cFile.DataLakeFolder}/x.xlsx";

            using (var str = await _dlsService.CreateFile(pathToFile))
            {

                using (var streamReader =  await _dlsService.OpenStream(filePath))
                {
                    StreamReader sr = new StreamReader(streamReader);
                    var parser = new CsvParser(sr);

                    //get the first row of csv as the header 
                    var header = parser.Read();
                    if (header == null)
                        return null;
                    var columns = header.ToList();
                    //check if there are empty columns
                    columns.RemoveAll(o => string.IsNullOrWhiteSpace(o));
                    int i = 1;
                    using (var report = new Application.Helpers.ExcelReportHelper(str)) // **this line gives me error** 
                    {
                        report.WriteHeader(columns);
                        if (i >= 1)
                        {
                            //if (parser.read == null) break, else continue to write the excel
                            //..work work work ...

                        }
                        report.Save();
                    }
                }
            }
            return new ObjectResult(new { fileCreated = pathToFile });
        }
        catch (Exception ex)
        {
            log.LogInformation("Processing request: " + ex.Message);
            return ErrorHandler.HandleException(ex, log);
        }
  }

than my excelhelper class is :

class ExcelReportHelper : IDisposable
{
    private ExcelPackage _package;
    private string _currentQueryName;

    public ExcelReportHelper(Stream destStream)
    {
        _package = new ExcelPackage(destStream); // **this is the line that raises the error**
        _package.Workbook.Worksheets.Add("Sheet1");
    }

    //bla bla bla
    //bla bla bla
 }

Any idea on how to approach to this problem?? I would very much need some help. Thanks :)

PS : This is the stack trace :

{System.NotSupportedException: Specified method is not supported.
        at Microsoft.Azure.DataLake.Store.AdlsOutputStream.get_Length()
        at OfficeOpenXml.ExcelPackage..ctor(Stream newStream)
        at Roar.EnrolService.Application.Helpers.ExcelReportHelper..ctor(Stream destStream) in  

C:\Projects\Roar\Roar.Ingestion\Roar.EnrolService\Application\Helpers\ExcelReportHelper.cs:line 16
   at 
 Roar.EnrolService.Functions.FileConversion.FromCsvToExcelFunction.Run(HttpRequest req, ILogger log) in C:\Projects\Roar\Roar.Ingestion\Roar.EnrolService\Functions\FileConversion\FromCsvToExcelFunction.cs:line 66}

Using ExcelPackage requires that you have Excel installed.

Probably it works on your environment since you have Excel, and does not work in Azure (not sure where in Azure you are running the code) since the code does not have access to Excel there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM