添加附件。附件名默认使用文件名

@param attachments 附件列表
@return
979812
public E attachments(File[] attachments) {
        for (File file : attachments) {
            addBinaryAttachment(file);
        }
        return getThis();
    }
666156
public static File file(String... names) {
		if (ArrayUtil.isEmpty(names)) {
			return null;
		}

		File file = null;
		for (String name : names) {
			if (file == null) {
				file = file(name);
			} else {
				file = file(file, name);
			}
		}
		return file;
	}
618136
public static List<File> listAttachmentFiles(File... directories) {
        return listFilesByRegex(
                AllureConfig.newInstance().getAttachmentFileRegex(),
                directories
        );
    }
173197
public void addAttachment(final String name, final DataSource filedata) {
		attachments.add(new AttachmentResource(name, filedata));
	}
1009313
public void renameAttachmentTo(String newAttachmentName) throws Exception {
		JSONObject doc = documentDescriptor.getJson();
		JSONObject _attachments = doc.optJSONObject("_attachments");
		JSONObject nunaliit_attachments = doc.getJSONObject(UploadConstants.KEY_DOC_ATTACHMENTS);
		JSONObject files = nunaliit_attachments.getJSONObject("files");

		// Verify no collision within nunaliit_attachments.files
		{
			Object obj = files.opt(newAttachmentName);
			if( null != obj ){
				throw new Exception("Can not rename attachment because of name collision");
			}
		}
		
		// Verify no collision within _attachments
		if( null != _attachments ){
			Object obj = _attachments.opt(newAttachmentName);
			if( null != obj ){
				throw new Exception("Can not rename attachment because of name collision");
			}
		}

		// Not allowed to move a stub		
		if( null != _attachments ){
			JSONObject att = _attachments.optJSONObject(attName);
			if( null != att ){
				throw new Exception("Can not rename attachment descriptor because file is already attached");
			}
		}
		
		// Move descriptor to new name
		String oldAttachmentName = attName;
		JSONObject descriptor = files.getJSONObject(oldAttachmentName);
		files.remove(oldAttachmentName);
		files.put(newAttachmentName, descriptor);
		attName = newAttachmentName;
		setStringAttribute(UploadConstants.ATTACHMENT_NAME_KEY,newAttachmentName);
		
		// Loop through all attachment descriptors, updating "source", "thumbnail"
		// and "original" attributes
		{
			Iterator<?> it = files.keys();
			while( it.hasNext() ){
				Object objKey = it.next();
				if( objKey instanceof String ){
					String key = (String)objKey;
					JSONObject att = files.getJSONObject(key);
					
					{
						String value = att.optString("source", null);
						if( oldAttachmentName.equals(value) ){
							att.put("source", newAttachmentName);
						}
					}

					{
						String value = att.optString("thumbnail", null);
						if( oldAttachmentName.equals(value) ){
							att.put("thumbnail", newAttachmentName);
						}
					}

					{
						String value = att.optString("originalAttachment", null);
						if( oldAttachmentName.equals(value) ){
							att.put("original", newAttachmentName);
						}
					}
				}
			}
		}
	}
1205660
def attachment(filename=nil)
      response['Content-Disposition'] = 'attachment'
      if filename
        params = '; filename="%s"' % File.basename(filename)
        response['Content-Disposition'] << params
        ext = File.extname(filename)
        content_type(ext) unless response['Content-Type'] or ext.empty?
      end
    end
591175
static String determineResourceName(final AttachmentResource attachmentResource, final boolean includeExtension) {
		final String datasourceName = attachmentResource.getDataSource().getName();

		String resourceName;

		if (!valueNullOrEmpty(attachmentResource.getName())) {
			resourceName = attachmentResource.getName();
		} else if (!valueNullOrEmpty(datasourceName)) {
			resourceName = datasourceName;
		} else {
			resourceName = "resource" + UUID.randomUUID();
		}
		if (includeExtension && !valueNullOrEmpty(datasourceName)) {
			@SuppressWarnings("UnnecessaryLocalVariable")
			final String possibleFilename = datasourceName;
			if (!resourceName.contains(".") && possibleFilename.contains(".")) {
				final String extension = possibleFilename.substring(possibleFilename.lastIndexOf("."));
				if (!resourceName.endsWith(extension)) {
					resourceName += extension;
				}
			}
		} else if (!includeExtension && resourceName.contains(".") && resourceName.equals(datasourceName)) {
			final String extension = resourceName.substring(resourceName.lastIndexOf("."));
			resourceName = resourceName.replace(extension, "");
		}
		return resourceName;
	}
294909
private function prepareAttachments($attachments = null)
    {
        $file_params = [];

        if ($attachments) {
            $counter = 1;

            foreach ($attachments as $attachment) {
                $path = is_array($attachment) ? $attachment[0] : $attachment;

                if (is_readable($path)) {
                    $file_params['attachment_'.$counter++] = $attachment;
                } else {
                    throw new FileNotReadable($attachment);
                }
            }
        }

        return $file_params;
    }
388212
public E attachment(File attachment, String name) {
        addBinaryAttachment(attachment, name);
        return getThis();
    }
791146
public void sortAttachments(ByteArrayInputStream byteArrayInputStream)  {
        List<String> attachmentNameList = new ArrayList<>();
        List<AttachmentData> attacmentList = getAttachments();
        List<AttachmentData> tempAttacmentList = new ArrayList<>();
        
        try{
            DocumentBuilderFactory domParserFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder domParser = domParserFactory.newDocumentBuilder();
            Document document = domParser.parse(byteArrayInputStream);
            byteArrayInputStream.close();
            NodeList fileLocationList = document.getElementsByTagName(NARRATIVE_ATTACHMENT_FILE_LOCATION);                       
            
           for(int itemLocation=0;itemLocation<fileLocationList.getLength();itemLocation++){
               String attachmentName =fileLocationList.item(itemLocation).getAttributes().item(0).getNodeValue();
               String[] name = attachmentName.split(KEY_VALUE_SEPARATOR);               
               String fileName =name[name.length-1];
               attachmentNameList.add(fileName);
           }
        }catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
        
        for(String attachmentName :attachmentNameList){
            for(AttachmentData attachment : attacmentList){                
                String[] names = attachment.getContentId().split(KEY_VALUE_SEPARATOR);               
                String fileName =names[names.length-1];
                if(fileName.equalsIgnoreCase(attachmentName)){
                    tempAttacmentList.add(attachment);
                }
            }
        }
        if(tempAttacmentList.size() > 0){
            attachments.clear();
            for(AttachmentData tempAttachment :tempAttacmentList){
                attachments.add(tempAttachment);
            } 
        }
    }
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;

    }
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
1089104
public function attachments($attachments = null) {
		if ($attachments === null) {
			return $this->_attachments;
		}

		return $this->setAttachments($attachments);
	}
414301
public Object getAttachment(String key) {
        return key == null ? null : attachments.get(key);
    }
298761
public function setAttachments($attachments) {
        /** @var AttachmentInterface $attachment */
        foreach ($attachments as $attachment) {
            $attachment->setMail($this);
        }

        $this->setData('attachments', $attachments);

        return $this;
    }
100707
public void addAttachment(Attachment attachment) {
        if (attachments == null || attachments == Collections.<Attachment>emptyList()) {
            attachments = new ArrayList<Attachment>();
        }

        attachments.add((AttachmentImpl) attachment);
    }
687412
public function validateAttachments(array $attachments)
    {
        $success = true;
        foreach ($attachments as $attachment) {
            if (!isset($attachment['filename']) || empty($attachment['filename'])) {
                $this->addError('attachments', 'Attachment must have a filename');
                $success = false;
            }

            if (!isset($attachment['mime_type']) || empty($attachment['mime_type'])) {
                $this->addError('attachments', 'Attachment must have a MIME type');
                $success = false;
            }

            if (!isset($attachment['contents'])) {
                $this->addError('attachments', 'Attachment must have contents');
                $success = false;
            }
        }

        return $success;
    }