code: public Attachment attachment(String name, BaseAsset asset,
                                   String filename, InputStream stream, Map<String, Object> attributes)
              throws AttachmentLengthExceededException,
              ApplicationUnavailableException {
          Attachment attachment = new Attachment(instance);
  
          attachment.setAsset(asset);
          attachment.setName(name);
          attachment.setFilename(filename);
          attachment.setContentType(MimeType.resolve(filename));
          addAttributes(attachment, attributes);
          attachment.save();
  
          if (stream != null) {
              attachment.readFrom(stream);
          }
  
          return attachment;
      }
docs: Create a new attachment with a name.
  
  @param name       The name of the attachment.
  @param asset      The asset this attachment belongs to.
  @param filename   The name of the original attachment file.
  @param stream     The read-enabled stream that contains the attachment
  content to upload.
  @param attributes additional attributes for the Attachment.
  @return A newly minted Attachment that exists in the VersionOne system.
  @throws AttachmentLengthExceededException
  if attachment is too long.
  @throws ApplicationUnavailableException
  if appears any problem with
  connection to service.