Adding attachments to subaward
559594
protected void addSubAwdAttachments(BudgetSubAwardsContract budgetSubAwards) {
        List<? extends BudgetSubAwardAttachmentContract> subAwardAttachments = budgetSubAwards.getBudgetSubAwardAttachments();
        for (BudgetSubAwardAttachmentContract budgetSubAwardAttachment : subAwardAttachments) {
            AttachmentData attachmentData = new AttachmentData();
            attachmentData.setContent(budgetSubAwardAttachment.getData());
            attachmentData.setContentId(budgetSubAwardAttachment.getName());
            attachmentData.setContentType(budgetSubAwardAttachment.getType());
            attachmentData.setFileName(budgetSubAwardAttachment.getName());
            addAttachment(attachmentData);
        }
    }
451523
private static void addAttachments(Map<String, ? extends Attachment> attachments,
                                   Map<String, Object> outMap,
                                   boolean shouldInline,
                                   int minRevPos) {
        // Use a LinkedHashMap which has "predictable iteration order" - this means that the
        // serializer will output the _attachments entries in the same order as the multipart bodies
        // Note that we have already sorted entries by their key (see below where a TreeMap is used)
        // se we only need *this* map to have an iteration order which is in the insertion order
        LinkedHashMap<String, Object> attsMap = new LinkedHashMap<String, Object>();
        outMap.put("_attachments", attsMap);

        // first sort by attachment name - this means that the
        // entries in the _attachments dictionary are in the same
        // order as the multiparts
        attachments = new TreeMap<String, Attachment>(attachments);
        for (Map.Entry<String, ? extends Attachment> att : attachments.entrySet()) {
            // we need to cast down to SavedAttachment, which we know is what the AttachmentManager gives us
            SavedAttachment savedAtt = (SavedAttachment) att.getValue();
            HashMap<String, Object> theAtt = new HashMap<String, Object>();
            try {
                // add the attachment if it's newer than the minimum revpos
                if (savedAtt.revpos > minRevPos) {
                    if (!shouldInline) {
                        theAtt.put("follows", true);
                    } else {
                        theAtt.put("follows", false);
                        // base64 encode this attachment
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        OutputStream bos = Base64OutputStreamFactory.get(baos);
                        InputStream fis = savedAtt.getInputStream();
                        try {
                            int bufSiz = 1024;
                            byte[] buf = new byte[bufSiz];
                            int n = 0;
                            do {
                                n = fis.read(buf);
                                if (n > 0) {
                                    bos.write(buf, 0, n);
                                }
                            } while (n > 0);
                            // out of paranoia, close and flush - docs don't say what you have to
                            // do to

                            // ensure all base64 is written, but close seems to do the right
                            // thing with
                            // the apache codec implementation
                            bos.flush();
                            bos.close();
                            theAtt.put("data", new String(baos.toByteArray(), "UTF-8")); //base64 of data
                        } finally {
                            IOUtils.closeQuietly(fis);
                        }
                    }
                    theAtt.put("length", savedAtt.length);
                    theAtt.put("encoded_length", savedAtt.encodedLength);
                    theAtt.put("content_type", savedAtt.type);
                    theAtt.put("revpos", savedAtt.revpos);
                    if (savedAtt.encoding != Attachment.Encoding.Plain) {
                        theAtt.put("encoding", savedAtt.encoding.toString().toLowerCase(Locale.ENGLISH));
                    }
                } else {
                    // if the revpos of the attachment is higher than the minimum, it's a stub
                    theAtt.put("stub", true);
                }
            } catch (IOException ioe) {
                // if we can't read the file containing the attachment then skip it
                // (this should only occur if someone tampered with the attachments directory
                // or something went seriously wrong)
                logger.log(Level.WARNING,String.format("Error reading attachment %s",att),ioe);
                continue;
            }
            // now we are done, add the attachment to the map
            attsMap.put(att.getKey(), theAtt);
        }
    }
1075670
def add(self, attachments):
        
        if attachments:
            if isinstance(attachments, (str, Path)):
                attachments = [attachments]
            if isinstance(attachments, (list, tuple, set)):
                # User provided attachments
                attachments_temp = [
                    self._attachment_constructor(attachment, parent=self)
                    for attachment in attachments]
            elif isinstance(attachments,
                            dict) and self._cloud_data_key in attachments:
                # Cloud downloaded attachments. We pass on_cloud=True
                # to track if this attachment is saved on the server
                attachments_temp = [self._attachment_constructor(
                    {self._cloud_data_key: attachment}, parent=self,
                    on_cloud=True)
                    for attachment in
                    attachments.get(self._cloud_data_key, [])]
            else:
                raise ValueError('Attachments must be a str or Path or a '
                                 'list, tuple or set of the former')

            self.__attachments.extend(attachments_temp)
            self._update_parent_attachments()
            self._track_changes()
1012796
def attachment_list
      container_classes = [SimpleFormAttachments.dom_class(:attachment_list)]
      container_classes << SimpleFormAttachments.dom_class(:attachment_list, :is_sortable) if sortable?
      template.content_tag :div, class: container_classes do
        @builder.simple_fields_for attribute_name do |attachment_fields|
          template.render(
            partial: attachment_fields.object.to_simple_form_partial_path, format: :html, layout: File.join('layouts', 'simple_form_attachments', 'attachment_layout'),
            locals: {
              attachment: attachment_fields.object,
              fields: attachment_fields,
              multiple: multiple?,
              form: @builder,
              relation_key: relation_key
            }
          )
        end
      end
    end
289595
def attach(self, attached_file, **attrs):
        
        return TaskAttachments(self.requester).create(
            self.project, self.id,
            attached_file, **attrs
        )
1161213
function addAttachment (docName, docRev) {
  const args = os.type() === 'Darwin' ? ['-l', '1'] : ['-b', '-n', '1']
  const stream = spawn('top', args).stdout
  const attName = `top-${Date.now()}.txt`
  const attContentType = 'text/plain'
  return db.addAttachment(dbName, docName, attName, docRev, attContentType, stream)
    .then(response => response.data.rev)
}
1228102
def supports_attachments(obj):
    
    if isinstance(obj, type):
        return issubclass(obj, SupportAttachment)

    if not isinstance(obj, SupportAttachment):
        return False

    if obj.id is None:
        return False

    return True
1111392
def add_attachment(attachment, name = '')
      # Is it a file object or a string (url)?
      if attachment.respond_to?(:path) && attachment.respond_to?(:read)
        client.post("/cards/#{id}/attachments", {
            file: attachment,
            name: name
          })
      else
        client.post("/cards/#{id}/attachments", {
            url: attachment,
            name: name
          })
      end
    end
1280495
def attachment_title(attachment)
      attachment.title.is_a?(Hash) ? translated_attribute(attachment.title) : attachment.title
    end
1182983
@InterfaceAudience.Private
    protected void addAttachment(Attachment attachment, String name) {
        Map<String, Object> attachments = (Map<String, Object>) properties.get("_attachments");
        if (attachments == null) {
            attachments = new HashMap<String, Object>();
        }
        attachments.put(name, attachment);
        properties.put("_attachments", attachments);
        if (attachment != null) {
            attachment.setName(name);
        }
    }
972061
public function attachment() {
		if ( $this->_post->post_parent ) {
			if ( $parent_post = get_post( $this->_post->post_parent ) ) {
				$this->addHierarchyOfSingularCrumbs( $parent_post );
				$this->addCrumb(
					get_the_title( $parent_post ),
					get_permalink( $parent_post )
				);
			}
		}
		$this->addCrumb(
			$this->label('attachment', get_the_title( $this->_post ) ),
			get_permalink( $this->_post )
		);
	}
82329
function updateSubmission($submission, $files) {
        $this->_flagSubmitted = false;

        if (empty($submission)) {
            $this->_submitValues = array();
        } else {
            foreach ($submission as $key => $s) {
                $type = $this->getCleanType($key, $s);
                $submission[$key] = $this->getCleanedValue($s, $type);
            }
            $this->_submitValues = $submission;
            $this->_flagSubmitted = true;
        }

        if (empty($files)) {
            $this->_submitFiles = array();
        } else {
            $this->_submitFiles = $files;
            $this->_flagSubmitted = true;
        }

        // need to tell all elements that they need to update their value attribute.
         foreach (array_keys($this->_elements) as $key) {
             $this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
         }
    }
328829
private void createAddContactSubForm() {
		add(new WHeading(HeadingLevel.H3, "Add a new contact"));

		WButton addBtn = new WButton("Add");
		addBtn.setAction(new Action() {
			@Override
			public void execute(final ActionEvent event) {
				addNewContact();
			}
		});
		addBtn.setImage("/image/address-book-new.png");
		newNameField.setDefaultSubmitButton(addBtn);

		WContainer container = new WContainer();
		container.add(newNameField);
		container.add(addBtn);

		WFieldLayout layout = new WFieldLayout();
		add(layout);
		layout.addField("New contact name", container);
		add(new WAjaxControl(addBtn, new AjaxTarget[]{repeater, newNameField}));
	}
228822
def _put_attachment_data(self, id, filename, data, content_type, include_online=False):
        """"""
        uri = '/'.join([self.base_url, self.name, id, 'Attachments', filename])
        params = {'IncludeOnline': 'true'} if include_online else {}
        headers = {'Content-Type': content_type, 'Content-Length': str(len(data))}
        return uri, params, 'put', data, headers, False
1310876
def attach(self, id, filename, url):
        
        Attachment = self.client.model('ir.attachment')
        return Attachment.add_attachment_from_url(
            filename, url, '%s,%s' % (self.model_name, id)
        )
433701
function attach($file,$alias=NULL,$cid=NULL) {
		if (!is_file($file))
			user_error(sprintf(self::E_Attach,$file),E_USER_ERROR);
		if ($alias)
			$file=[$alias,$file];
		$this->attachments[]=['filename'=>$file,'cid'=>$cid];
	}
394462
function AddAttachment($path, $name = "", $encoding = "base64", $type = "application/octet-stream") {
      if(!@is_file($path))
      {
         $this->error_handler(sprintf("Could not find %s file on filesystem", $path));
         return false;
      }

      $filename = basename($path);
      if($name == "")
         $name = $filename;

      // Append to $attachment array
      $cur = count($this->attachment);
      $this->attachment[$cur][0] = $path;
      $this->attachment[$cur][1] = $filename;
      $this->attachment[$cur][2] = $name;
      $this->attachment[$cur][3] = $encoding;
      $this->attachment[$cur][4] = $type;
      $this->attachment[$cur][5] = false; // isStringAttachment

      return true;
   }