public ItemRequest < Attachment > createOnTask ( String task , InputStream fileContent , String fileName , String fileType ) { MultipartContent . Part part = new MultipartContent . Part ( ) . setContent ( new InputStreamContent ( fileType , fileContent ) ) . setHeaders ( new HttpHeaders ( ) . set ( "Content-Disposition" , String . format ( "form-data; name=\"file\"; filename=\"%s\"" , fileName ) // TODO: escape fileName? ) ) ; MultipartContent content = new MultipartContent ( ) . setMediaType ( new HttpMediaType ( "multipart/form-data" ) . setParameter ( "boundary" , UUID . randomUUID ( ) . toString ( ) ) ) . addPart ( part ) ; String path = String . format ( "/tasks/%s/attachments" , task ) ; return new ItemRequest < Attachment > ( this , Attachment . class , path , "POST" ) . data ( content ) ; }
Upload a file and attach it to a task