0

I'm looking to create some custom API apps for the sole purpose of creating a/some Logic Apps. With these custom API Apps, I want to pass around files. These files will usually be CSV, ZIP, Excel, TXT, and some other formats - unknown to the consumer until the file is returned (i.e. the client does not dictate the file format).

How does one do something like this in a way that's compatible with Swagger/Swashbuckle, Web API, and Logic Apps? I'll ultimately be tying this into an FTP connector, Dropbox, Onebox, or other file-storage connector.

Does following something like this work or do I need to take a different approach? For example, should I simply work with JSON objects and let my binary be base64-encoded by using a model like this?

public class BinaryFile
{
    public string FileName { get; set; }
    public string FileExtension { get; set; }
    public string DeducedMimeType { get; set; }
    public int FileSize { get; set; }
    public string FileEncoding { get; set; }
    public byte[] FileBinary { get; set; }
}

(this question is cross-posted to MSDN Forums)

Community
  • 1
  • 1
Jaxidian
  • 13,081
  • 8
  • 83
  • 125

1 Answers1

0

The approach I've taken is what I posed in the question with the BinaryFile class. I've broken it out into a few classes. I'm not done - I have some improvements to make still but this is functional right now.

Main class with some common fields:

public class FileResult<T>
{
    public string Source { get; set; }
    public T File { get; set; }
    public IList<string> ErrorMessages { get; set; } = new List<string>();
    public bool IsSuccessful { get; set; } = false;
}

This is the <T> in my FileResult<T> class:

public class CsvFile
{
    public string Filename { get; set; }
    public string Contents { get; set; }
    public int Size { get; set; }
}

public class BinaryFile
{
    public string FileName { get; set; }
    public string FileExtension { get; set; }
    public string DeducedMimeType { get; set; }
    public int Size { get; set; }
    public byte[] Contents { get; set; }
}

Note that in my case, there are some times when I am working with multiple files and not just one, so what could appear to be some common fields are still within the type passed in as the <T> so I can have something like FileResult<IEnumerable<CsvFile>>.

This is all playing nicely with Swagger, Swashbuckle, Web API, Azure API Apps, and Azure Logic Apps. For the cases where I am returning multiple files to my Azure Logic App, I use the fairly hidden splitsOn feature (that also has some designer bugs, so be careful!) to easily iterate over all of the files. It works very nicely.

Jaxidian
  • 13,081
  • 8
  • 83
  • 125