All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csharp-functions.libraries.httpclient.FileParameter.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>partial_header}}

using System.IO;

namespace {{packageName}}.Client
{

    /// 
    /// Represents a File passed to the API as a Parameter, allows using different backends for files
    /// 
    public class FileParameter
    {
        /// 
        /// The filename
        /// 
        public string Name { get; set; } = "no_name_provided";

        /// 
        /// The content of the file
        /// 
        public Stream Content { get; set; }

        /// 
        /// Construct a FileParameter just from the contents, will extract the filename from a filestream
        /// 
        ///  The file content 
        public FileParameter(Stream content)
        {
            if (content is FileStream fs)
            {
                Name = fs.Name;
            }
            Content = content;
        }

        /// 
        /// Construct a FileParameter from name and content
        /// 
        /// The filename
        /// The file content
        public FileParameter(string filename, Stream content)
        {
            Name = filename;
            Content = content;
        }

        /// 
        /// Implicit conversion of stream to file parameter. Useful for backwards compatibility.
        /// 
        /// Stream to convert
        /// FileParameter
        public static implicit operator FileParameter(Stream s) => new FileParameter(s);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy