Exemplo n.º 1
0
        private static void WriteFile(Stream requestStream, RequestFileInfo fileInfo)
        {
            var header = string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\nContent-Transfer-Encoding: binary\r\n\r\n",
                                       Path.GetFileNameWithoutExtension(fileInfo.Name),
                                       Path.GetFileName(fileInfo.Name),
                                       fileInfo.ContentType ?? "application/octet-stream");

            WriteUtf8String(requestStream, header);
            requestStream.Write(fileInfo.Body, 0, fileInfo.Body.Length);
        }
Exemplo n.º 2
0
        private static RequestFileInfo GetAsAttachment(MIME_Entity entity)
        {
            var attachment = new RequestFileInfo
            {
                Body = ((MIME_b_SinglepartBase)entity.Body).Data
            };

            if (!string.IsNullOrEmpty(entity.ContentDisposition.Param_FileName))
            {
                attachment.Name = entity.ContentDisposition.Param_FileName;
            }
            else if (!string.IsNullOrEmpty(entity.ContentType.Param_Name))
            {
                attachment.Name = entity.ContentType.Param_Name;
            }

            attachment.ContentType = MimeMapping.GetMimeMapping(attachment.Name);

            return(attachment);
        }
Exemplo n.º 3
0
        private static RequestFileInfo GetAsAttachment(MIME_Entity entity)
        {
            var attachment = new RequestFileInfo
                {
                    Body = ((MIME_b_SinglepartBase)entity.Body).Data
                };

            if (!string.IsNullOrEmpty(entity.ContentDisposition.Param_FileName))
            {
                attachment.Name = entity.ContentDisposition.Param_FileName;
            }
            else if (!string.IsNullOrEmpty(entity.ContentType.Param_Name))
            {
                attachment.Name = entity.ContentType.Param_Name;
            }

            attachment.ContentType = MimeMapping.GetMimeMapping(attachment.Name);

            return attachment;
        }
Exemplo n.º 4
0
        private static void WriteFile(Stream requestStream, RequestFileInfo fileInfo)
        {
            var header = string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\nContent-Transfer-Encoding: binary\r\n\r\n",
                                       Path.GetFileNameWithoutExtension(fileInfo.Name),
                                       Path.GetFileName(fileInfo.Name),
                                       fileInfo.ContentType ?? "application/octet-stream");

            WriteUtf8String(requestStream, header);
            requestStream.Write(fileInfo.Body, 0, fileInfo.Body.Length);
        }