0

Filestreamresult is resulting in 500 internal server error on Pivotal Cloud Foundry (PCF). When I run angular app on localhost and .netcore webapi on localhost I am able to download the file but on cloudfoundry it does not work.

I have researched and found some solutions but none worked in my case. I have tried following links https://www.syncfusion.com/forums/125221/asp-net-core-sending-a-generated-pdf-directly-to-browser https://weblogs.thinktecture.com/pawel/2017/03/aspnet-core-webapi-performance.html

  • I have tried returning File(mstrm,"text/plain") works on localhost but not on PCF.
  • I have also tried File(mStrm, "application/octet-stream") works on localhost but not on PCF.
  • My other API endpoints work on PCF, just this one is causing the error.
  • Also checked logs on PCF but it only shows that it resulted in 500 error.
  • This api is using dotnet_core_buildpack and is hosted on cflinux.

    public FileStreamResult appConfigure([FromBody] Test test) {

        var testFile = _test.generateScript(test);
        MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(testFile));
        mStrm.Position = 0;
        return new FileStreamResult(mStrm, "text/plain")
        {
            FileDownloadName = test.testName + ".txt"
        };
    }
    

result should be test.txt file returned with http 200 response. But I am receiving 500 error POST https://testapp.apps.pcf.testapp.com/api/test/genscript 500 (Internal Server Error)

Have been stuck on this for last 2 days, any help is much appreciated :)

powernit
  • 119
  • 1
  • 3
  • 16
  • 1
    ++exception message please. Guessing and fortune telling sucks – Tseng Jul 24 '19 at 06:04
  • Thanks Tseng, Actually this code is working. I need to work on PCF error logging in my application. But the error message is Cannot find the File at location /template/ TestSctiptTemplate.txt. Locally it is able to find it but on PCF it is not finding it. Do you know how can i route to that file on PCF ? – powernit Jul 24 '19 at 06:58
  • Then thats your error. Missing folder, uncomplete deployment? Do you include that folder when publishing your application? Is it created inside the publishing artifacts? Did you try adding a dummy file to that folder and have it added to publishing? GitHub / deployments sometimes don't publish empty folders – Tseng Jul 24 '19 at 07:06
  • 1
    [This](https://stackoverflow.com/a/54765877/455493) answer shows how to add folders to the publishing output (via `` tag in csproj – Tseng Jul 24 '19 at 07:07
  • 1
    `/template/` isn't going to exist in your container and you cannot write to that location on CF. Your app runs as a non-root user, so you don't have permissions to that location. You need to put your templates somewhere where the user running your app does have permissions. The easiest location would be under $HOME or $PWD (both happen to point to the same place), so `$HOME/templates` or `$PWD/templates` which would be a `templates/` directory under the root of the application files you push. – Daniel Mikusa Jul 24 '19 at 14:45

0 Answers0