Exemplo n.º 1
0
 public string Decode()
 {
     if (MultipartFormDataItem == null)
     {
         throw new ContentDecodingException("MultipartFormDataItem must not be null");
     }
     if (!CanDecode)
     {
         throw new ContentDecodingException("Could not decode content");
     }
     byte[] bytes = MultipartFormDataItem.Content;
     if (!string.IsNullOrEmpty(MultipartFormDataItem.ContentTransferEncoding))
     {
         var charDecoder =
             ContentTransferDecoderFactory.FindAndCreateInstance <char>(MultipartFormDataItem);
         if (charDecoder != null)
         {
             return(new string(charDecoder.Decode(MultipartFormDataItem).ToArray()));
         }
         var byteDecoder =
             ContentTransferDecoderFactory.FindAndCreateInstance <byte>(MultipartFormDataItem);
         if (byteDecoder == null)
         {
             throw new ContentDecodingException("Could not decode content");
         }
         bytes = byteDecoder.Decode(MultipartFormDataItem).ToArray();
     }
     return(GetEncodingFromCharSet().GetString(bytes));
 }
Exemplo n.º 2
0
 public Image Decode()
 {
     if (MultipartFormDataItem == null)
     {
         throw new ContentDecodingException("MultipartFormDataItem must not be null");
     }
     if (!CanDecode)
     {
         throw new ContentDecodingException("Could not decode content");
     }
     byte[] bytes = MultipartFormDataItem.Content;
     if (!string.IsNullOrEmpty(MultipartFormDataItem.ContentTransferEncoding))
     {
         var decoder =
             ContentTransferDecoderFactory.FindAndCreateInstance <byte>(MultipartFormDataItem);
         if (decoder == null)
         {
             throw new ContentDecodingException("Could not decode content");
         }
         bytes = decoder.Decode(MultipartFormDataItem).ToArray();
     }
     return(Image.FromStream(new MemoryStream(bytes)));
 }