Add an attachment.
340612
public function addAttachment($path, $name = null, $mime = true, $encoding = true)
    {
        $cid = static::generateId($this->client());
        $filename = basename($path);
        $this->_attachments[$path] = [
            'filename'    => $name ?: $filename,
            'disposition' => 'attachment',
            'mime'        => $mime,
            'headers'     => ['Content-ID: ' . $cid]
        ];
        return $cid;
    }
870877
protected function maybeShiftAttachment() {

		if ( ! in_the_loop() || 'attachment' !== get_post_type() ) {
			return;
		}

		if ( in_array( $this->name, [ 'entry', 'post', 'entry/archive', 'entry/single' ] ) ) {

			remove_filter( 'the_content', 'prepend_attachment' );

		} elseif ( 'embed' === $this->name ) {

			remove_filter( 'the_content',       'prepend_attachment'          );
			remove_filter( 'the_excerpt_embed', 'wp_embed_excerpt_attachment' );
		}
	}
222435
def attachment_upload(instance, filename):
    """"""
    return 'attachments/{app}_{model}/{pk}/{filename}'.format(
        app=instance.content_object._meta.app_label,
        model=instance.content_object._meta.object_name.lower(),
        pk=instance.content_object.pk,
        filename=filename,
    )
601080
public function attach($attachment)
    {

        // if string
        if (is_string($attachment)) {
            $attachment = [$attachment, ''];
        }

        // if array
        if (is_array($attachment)) {
            list($name, $type) = $attachment;
        }

        if ($attachment instanceof PhpMailerAttachmentInterface) {
            $filename = $attachment->getFile();
            $name = ($attachment->getNewName()) ? $attachment->getNewName() : $filename;
            $type = $attachment->getType();
        }


        $this->mailer->addAttachment($filename, $name, 'base64', $type);
        return $this;

    }
262251
def create_on_task(self, task_id, file_content, file_name, file_content_type=None, **options):
        """"""
        path = '/tasks/%d/attachments' % (task_id)
        return self.client.request('post', path, files=[('file', (file_name, file_content, file_content_type))], **options)
229576
def pickAttachment(self):
        
        filename = QFileDialog.getOpenFileName(self.window(),
                                               'Select Attachment',
                                               '',
                                               'All Files (*.*)')
        
        if type(filename) == tuple:
            filename = nativestring(filename[0])
        
        filename = nativestring(filename)
        if filename:
            self.addAttachment(os.path.basename(filename), filename)
1285532
def attach(self, volume_id, instance_id, device_path):
        """"""
        return self.call("AttachVolume",
                         VolumeId=volume_id, InstanceId=instance_id,
                         Device=device_path)
650107
public function addAttachment($attachment)
    {
        if ($attachment instanceof \SplFileObject && $attachment->isFile() && $attachment->isReadable()) {
            $file['filename'] = method_exists($attachment, 'getAttachmentFilename') ?
                $attachment->getAttachmentFilename() :
                $attachment->getBasename();

            $file['is_embedded'] = method_exists($attachment, 'getIsEmbedded') ? $attachment->getIsEmbedded() : false;
            $file['id'] = method_exists($attachment, 'getId') ? $attachment->getId() : null;

            if (method_exists($attachment, 'getMimeType')) {
                $file['mime_type'] = $attachment->getMimeType();
            } else {
                $resource = finfo_open(FILEINFO_MIME_TYPE);
                $file['mime_type'] = finfo_file($resource, $attachment->getRealPath());
            }

            $file['contents'] = '';
            while (!$attachment->eof()) {
                $file['contents'] .= $attachment->fgets();
            }
            $file['contents'] = base64_encode($file['contents']);

            $this->attachments[] = $file;
        } elseif (is_array($attachment)) {
            $this->attachments[] = $attachment;
        }

        return $this;
    }
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
128537
public void add(Matcher matcher, T attachment)
    {
        add(matcher);
        map.add(matcher, attachment);
    }
1009485
public function add_attachment($message, $name =  "", $ctype =  "application/octet-stream", $encode =  "base64", $charset='', $contentid='') {
    $this->parts[] = array ( "ctype" => $ctype,
                             "message" => $message,
                             "encode" => $encode,
                             "name" => $name,
                             "charset" => $charset,
                             "contentid" => $contentid
                            );
  }
116005
public function addFile(string $filename, string $name = null, string $mimeType = null): void
    {
        $attachment = new FileAttachment();
        $attachment->filename = $filename;
        if ($name !== null) {
            $attachment->name = $name;
        }
        if ($mimeType !== null) {
            $attachment->mimeType = $mimeType;
        }
        $this->set($attachment);
    }
468735
private void addAttachment(Multipart multipart, Attachment attachment) throws AttachmentResourceHandlerException {
		MimeBodyPart part = new MimeBodyPart();
		try {
			part.setFileName(attachment.getResource().getName());
			part.setDisposition(attachment.getDisposition());
			part.setDescription(attachment.getDescription());
			part.setContentID(attachment.getContentId());
			attachmentHandler.setData(part, attachment.getResource(), attachment);
			multipart.addBodyPart(part);
		} catch (MessagingException e) {
			throw new AttachmentResourceHandlerException("Failed to attach " + attachment.getResource().getName(), attachment, e);
		}
	}
844050
def attach_related_file(self, path, mimetype=None):
        """"""
        filename = os.path.basename(path)
        content = open(path, 'rb').read()
        self.attach_related(filename, content, mimetype)
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;
   }
898560
def put_attachment(self, id, filename, file, content_type, include_online=False):
        """"""
        return self.put_attachment_data(id, filename, file.read(), content_type, include_online=include_online)
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);
        }
    }