Example #1
0
        private void WriteFilePart(IHttpStreamable httpStream, bool prepare, string key, FileLink value)
        {
            FileInfo fileInfo = (FileInfo)value.GetInfo();
            string   fileName = fileInfo.Name;

            if (NoMediaExtension)
            {
                fileName = StringFunc.Substring(fileName, 0, fileName.IndexOf(fileInfo.Extension));
            }
            httpStream.WriteLine("Content-Disposition: form-data; name=\"" + key + "\"; filename=\"" + fileName + "\"");
            httpStream.WriteLine("Content-Type: " + MimeType.GetByFile(value).Notation);

            if (!Chunked)
            {
                httpStream.WriteLine("Content-Transfer-Encoding: binary");
            }
            httpStream.WriteLine();
            httpStream.FlushUnderlying();

            if (!prepare)
            {
                WriteFile(httpStream, value);
            }
            httpStream.WriteLine();
            httpStream.FlushUnderlying();
        }
Example #2
0
 private void WriteOctetStreamPart(IHttpStreamable httpStream, string key)
 {
     httpStream.WriteLine("Content-Disposition: form-data; name=\"" + key + "\"; filename=\"\"");
     httpStream.WriteLine("Content-Type: application/octet-stream");
     httpStream.WriteLine();
     httpStream.WriteLine();
     httpStream.FlushUnderlying();
 }
Example #3
0
 private void WriteStringPart(IHttpStreamable httpStream, string key, string value)
 {
     httpStream.WriteLine("Content-Disposition: form-data; name=\"" + key + "\"");
     //httpStream.writeLine("Content-Type: text/plain; charset=UTF-8");
     httpStream.WriteLine();
     httpStream.WriteLine(value);
     httpStream.FlushUnderlying();
 }
Example #4
0
        protected override void Build(IHttpStreamable httpStream, bool prepare)
        {
            fileSize = 0;
            bool lastEntryWasFile = false;

            foreach (AttributeKeyValuePair kvp in kvpContainer.Kvps)
            {
                string key = Encoding.UTF8.GetString(Encoding.Default.GetBytes(kvp.Key));
                lastEntryWasFile = true;

                httpStream.WriteLine("--" + Boundary);

                if (kvp.Value is null)
                {
                    WriteOctetStreamPart(httpStream, key);
                    continue;
                }
                if (kvp.Value is byte[])
                {
                    WriteOctetStreamPart(httpStream, prepare, key, (byte[])kvp.Value);
                    fileSize += ((byte[])kvp.Value).Length;
                    continue;
                }
                if (kvp.Value is FileLink)
                {
                    if (Chunked)
                    {
                        if (ChunkHandler is null)
                        {
                            ChunkHandler = new ChunkHandler((FileLink)kvp.Value);
                        }
                        ChunkHandler.PrepareTransfer();
                        fileSize += ChunkHandler.ChunkSize;
                    }
                    else
                    {
                        fileSize += ((FileInfo)((FileLink)kvp.Value).GetInfo()).Length;
                    }
                    WriteFilePart(httpStream, prepare, key, (FileLink)kvp.Value);
                    continue;
                }
                string value = kvp.Value is string?(string)kvp.Value : kvp.Value.ToString();
                value = Encoding.UTF8.GetString(Encoding.Default.GetBytes(value));

                lastEntryWasFile = false;

                WriteStringPart(httpStream, key, value);
            }
            if (lastEntryWasFile)
            {
                httpStream.WriteLine();
                httpStream.FlushUnderlying();
            }
            httpStream.WriteLine("--" + Boundary + "--");
        }
Example #5
0
        private void WriteOctetStreamPart(IHttpStreamable httpStream, bool prepare, string key, byte[] payload)
        {
            httpStream.WriteLine("Content-Disposition: form-data; name=\"" + key + "\"; filename=\"blob\"");
            httpStream.WriteLine("Content-Type: application/octet-stream");
            httpStream.WriteLine();

            if (!prepare)
            {
                httpStream.Write(payload);
            }
            httpStream.WriteLine();
            httpStream.FlushUnderlying();
        }