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(); }
public ChunkHandler(FileLink fileLink) { FileLink = fileLink; fileSize = ((FileInfo)fileLink.GetInfo()).Length; chunks = fileSize <= HttpConfig.ChunkSize ? 1 : (fileSize / HttpConfig.ChunkSize); fileInputStream = new FileStream(fileLink.Path, FileMode.Open); if (chunks > 1) { restChunkSize = fileSize % (chunks * HttpConfig.ChunkSize); if (restChunkSize > 0) { chunks++; } } }
public StreamBody(FileLink fileLink, bool raw = false) : base(EncType.Stream) { this.fileLink = fileLink; this.fileInfo = (FileInfo)fileLink.GetInfo(); this.raw = raw; }