score:25

Accepted answer

1) it is ok to put uploading into separate method, it could also be put into a separate class for handling blob operations

2) file is the name of one of the controllers methods, if you want to reference the file class from system.io namespace, you need to fully qualify the name

filestream uploadfilestream = system.io.file.openread(localfilepath);

to the other compile error, you need to return something from the uploadtoblob method, now it does not return anything from the try block

3) file type validation can be put into the controller action method

4) it depends on what you plan to do with the text and how are you going to use it. would it be a new action of the controller (a new api endpoint)?

5) you could create a new api endpoint for downloading files

update:

for word replacement you could use a similar method:

private stream findmostfrequentwordandreplaceit(stream inputstream)
{
    using (var sr = new streamreader(inputstream, encoding.utf8)) // what is the encoding of the text? 
    {
        var alltext = sr.readtoend(); // read all text into memory
        // todo: find most frequent word in alltext
        // replace the word alltext.replace(oldvalue, newvalue, stringcomparison)
        var resulttext = alltext.replace(...);

        var result = new memorystream();
        using (var sw = new streamwriter(result))
        {
            sw.write(resulttext);
        }
        result.position = 0;
        return result;
    }
}

it would be used in your post method this way:

using (var stream = formfile.openreadstream())
{
    var streamwithreplacement = findmostfrequentwordandreplaceit(stream);

    // upload the replaced text:
    (uploadsuccess, uploadeduri) = await uploadtoblob(formfile.filename, null, streamwithreplacement);

}

score:5

you probably have this method inside mvc controller in which file method exists. add in your code system.io.file instead of file


Related Query

More Query from same tag