Skip to content
This repository
Browse code

Merge pull request #74 from steppenwells/master

Adds the ability to add a byte array to a multipart post
  • Loading branch information...
commit 99beaa0d557ff7a0949e0fbe0452a7386605934c 2 parents c35f9cd + 2a418c7
Nathan Hamblen authored April 23, 2012

Showing 1 changed file with 16 additions and 8 deletions. Show diff stats Hide diff stats

  1. 24  mime/src/main/scala/Mime.scala
24  mime/src/main/scala/Mime.scala
@@ -4,12 +4,12 @@ import java.io.{FilterOutputStream, OutputStream}
4 4
 import org.apache.http.HttpEntity
5 5
 import org.apache.http.entity.HttpEntityWrapper
6 6
 import org.apache.http.entity.mime.{FormBodyPart, MultipartEntity}
7  
-import org.apache.http.entity.mime.content.{FileBody, StringBody, InputStreamBody, ContentBody}
8 7
 
9 8
 import java.io.{File, InputStream}
10 9
 import java.nio.charset.Charset
  10
+import org.apache.http.entity.mime.content._
11 11
 
12  
-/** Mime module for multipart form posting. Note that when using an InputStream generator, 
  12
+/** Mime module for multipart form posting. Note that when using an InputStream generator,
13 13
   chuncked encoding will be used with no Content-Length header and the stream will be closed
14 14
   after posting. It is therefore highly recommended that your generator always return a new 
15 15
   stream instance, or a Request descriptor referencing it will fail after its first use. */
@@ -31,20 +31,28 @@ object Mime {
31 31
     }
32 32
 
33 33
     /** Add file to multipart post, will convert other post methods to multipart */
34  
-    def <<* (name: String, file: File) = 
  34
+    def <<* (name: String, file: File) =
35 35
       add(name, new FileBody(file))
36 36
     /** Add file with content-type to multipart post, will convert other post methods to multipart */
37  
-    def <<* (name: String, file: File, content_type: String) = 
  37
+    def <<* (name: String, file: File, content_type: String) =
38 38
       add(name, new FileBody(file, content_type))
39 39
 
40  
-    /** Add stream generator with content-type to multipart post, will convert other post methods to multipart */
41  
-    def <<* (name: String, file_name: String, stream: () => InputStream, content_type: String) = 
  40
+    /** Add stream generator to multipart post, will convert other post methods to multipart. */
  41
+    def <<* (name: String, file_name: String, stream: () => InputStream, content_type: String) =
42 42
       add(name, new InputStreamBody(stream(), content_type, file_name))
43 43
 
44  
-    /** Add stream generator to multipart post, will convert other post methods to multipart. */
45  
-    def <<* (name: String, file_name: String, stream: () => InputStream) = 
  44
+    /** Add stream generator with content-type to multipart post, will convert other post methods to multipart */
  45
+    def <<* (name: String, file_name: String, stream: () => InputStream) =
46 46
       add(name, new InputStreamBody(stream(), file_name))
47 47
 
  48
+    /** Add byte array to multipart post, will convert other post methods to multipart */
  49
+    def <<* (name: String, file_name: String, bytes: Array[Byte]) =
  50
+      add(name, new ByteArrayBody(bytes, file_name))
  51
+
  52
+    /** Add byte array with content-type to multipart post, will convert other post methods to multipart */
  53
+    def <<* (name: String, file_name: String, bytes: Array[Byte], content_type: String) =
  54
+      add(name, new ByteArrayBody(bytes, content_type, file_name))
  55
+
48 56
     private def mime_ent: Mime.Entity = {
49 57
       def newent = new MultipartEntity with Mime.Entity {
50 58
         val charset = Charset.forName(r.defaultCharset)

0 notes on commit 99beaa0

Please sign in to comment.
Something went wrong with that request. Please try again.