When displaying or sending the attachment the file contents are fetched
using this method. This is also called by the attachment_display hook.
333652
function get($args)
    {
        $cache = $this->get_cache();
        $data  = $cache->read($args['id']);

        if ($data !== null && $data !== false) {
            $args['data'] = base64_decode($data);
            $args['status'] = true;
        }
        else {
            $args['status'] = false;
        }

        return $args;
    }
1223853
def FetchFileContent(self):
    
    if not self.state.pending_files:
      return

    # Check what blobs we already have in the blob store.
    blob_hashes = []
    for file_tracker in itervalues(self.state.pending_files):
      for hash_response in file_tracker.get("hash_list", []):
        blob_hashes.append(rdf_objects.BlobID.FromBytes(hash_response.data))

    # This is effectively a BlobStore call.
    existing_blobs = data_store.BLOBS.CheckBlobsExist(blob_hashes)

    self.state.blob_hashes_pending = 0

    # If we encounter hashes that we already have, we will update
    # self.state.pending_files right away so we can't use an iterator here.
    for index, file_tracker in list(self.state.pending_files.items()):
      for i, hash_response in enumerate(file_tracker.get("hash_list", [])):
        # Make sure we read the correct pathspec on the client.
        hash_response.pathspec = file_tracker["stat_entry"].pathspec

        if existing_blobs[rdf_objects.BlobID.FromBytes(hash_response.data)]:
          # If we have the data we may call our state directly.
          self.CallStateInline(
              messages=[hash_response],
              next_state="WriteBuffer",
              request_data=dict(index=index, blob_index=i))
        else:
          # We dont have this blob - ask the client to transmit it.
          self.CallClient(
              server_stubs.TransferBuffer,
              hash_response,
              next_state="WriteBuffer",
              request_data=dict(index=index, blob_index=i))
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);
		}
	}
772444
def get_attachment_info(self, attachment):
        

        attachment_uid = api.get_uid(attachment)
        attachment_file = attachment.getAttachmentFile()
        attachment_type = attachment.getAttachmentType()
        attachment_icon = attachment_file.icon

        if callable(attachment_icon):
            attachment_icon = attachment_icon()

        return {
            'keywords': attachment.getAttachmentKeys(),
            'size': self.get_attachment_size(attachment),
            'name': attachment_file.filename,
            'Icon': attachment_icon,
            'type': api.get_uid(attachment_type) if attachment_type else '',
            'absolute_url': attachment.absolute_url(),
            'UID': attachment_uid,
            'report_option': attachment.getReportOption(),
            'analysis': '',
        }
48472
def get(self, attach, *args, **kwargs):
        
        response = self.make_response(*args, **kwargs)  # type: Response
        response.content_type = self.get_content_type(*args, **kwargs)

        if attach:
            filename = self.get_filename(*args, **kwargs)
            if not filename:
                filename = "file.bin"
            headers = response.headers
            headers.add("Content-Disposition", "attachment", filename=filename)

        self.set_cache_headers(response)
        return response
112961
def show(self):
        
        url = self.request.getURL()
        # XXX: Hack to show the viewlet only on the AR base_view
        if not any(map(url.endswith, ["base_view", "manage_results"])):
            return False
        return self.attachments_view.user_can_add_attachments() or \
               self.attachments_view.user_can_update_attachments()
754426
public function read()
    {
        $lines = readLines($this->fileName, $this->fileEncoding);
        $fetch = array();

        foreach ($lines as $line) {
            $fields = preg_split('/\s+/', $line);
            if (count($fields) == 3) {
                array_push(
                    $fetch,
                    array('url' => $fields[0],
                          'length' => $fields[1],
                          'filename' => $fields[2])
                );
            }
        }
        $this->data = $fetch;
    }
1022147
def file_view(self, request, field_entry_id):
        
        model = self.fieldentry_model
        field_entry = get_object_or_404(model, id=field_entry_id)
        path = join(fs.location, field_entry.value)
        response = HttpResponse(content_type=guess_type(path)[0])
        f = open(path, "r+b")
        response["Content-Disposition"] = "attachment; filename=%s" % f.name
        response.write(f.read())
        f.close()
        return response
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 )
		);
	}
786278
private function fetchLocal() {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $this->mime = finfo_file($finfo, $this->path);
        finfo_close($finfo);
        $this->data = file_get_contents($this->path, FILE_USE_INCLUDE_PATH);
    }
1349478
def file_to_attachment(filename, filehandler=None):
    
    if filehandler:
        return {'_name': filename,
                'content': base64.b64encode(filehandler.read())
        }
    with open(filename, 'rb') as _file:
        return {'_name': filename,
                'content': base64.b64encode(_file.read())
        }
518324
private byte[] getUploadFileContent(RequestElements requestElements) throws FMSException {
		Attachable attachable = (Attachable) requestElements.getEntity();
		InputStream docContent = requestElements.getUploadRequestElements().getDocContent();
		
		// gets the mime value form the filename
		String mime = getMime(attachable.getFileName(), ".");
		// if null then gets the mime value from content-type of the file
		mime = (mime != null) ? mime : getMime(attachable.getContentType(), "/");
		if (isImageType(mime)) {
			return getImageContent(docContent, mime);
		} else {
			return getContent(docContent);
		}
	}
315559
public String getContent() {
        if (content != null) {
            return context != null ? context.replaceDynamicContentInString(content) : content;
        } else if (StringUtils.hasText(getContentResourcePath()) && getContentType().startsWith("text")) {
            try {
                String fileContent = FileUtils.readToString(new PathMatchingResourcePatternResolver().getResource(getContentResourcePath()).getInputStream(), Charset.forName(charsetName));
                return context != null ? context.replaceDynamicContentInString(fileContent) : fileContent;
            } catch (IOException e) {
                throw new CitrusRuntimeException("Failed to read SOAP attachment file resource", e);
            }
        } else {
            try {
                byte[] binaryData = FileCopyUtils.copyToByteArray(getDataHandler().getInputStream());
                if (encodingType.equals(SoapAttachment.ENCODING_BASE64_BINARY)) {
                    return Base64.encodeBase64String(binaryData);
                } else if (encodingType.equals(SoapAttachment.ENCODING_HEX_BINARY)) {
                    return Hex.encodeHexString(binaryData).toUpperCase();
                } else {
                    throw new CitrusRuntimeException(String.format("Unsupported encoding type '%s' for SOAP attachment - choose one of %s or %s",
                            encodingType, SoapAttachment.ENCODING_BASE64_BINARY, SoapAttachment.ENCODING_HEX_BINARY));
                }
            } catch (IOException e) {
                throw new CitrusRuntimeException("Failed to read SOAP attachment data input stream", e);
            }
        }
    }
938422
protected function decodeAttachments()
    {
        foreach ($this->attachments as $key => $attachment) {
            /*
             * Decode body
             */
            switch ($attachment->info->structure->encoding) {
                case 3:
                    $this->attachments[$key]->body = imap_base64($attachment->body);
                    break;
                case 4:
                    $this->attachments[$key]->body = quoted_printable_decode($attachment->body);
                    break;
            }
            /*
             * Decode name
             */
            $this->attachments[$key]->name = $this->mimeHeaderDecode($attachment->name);
        }
    }
480977
def render_to_response(self, context, **response_kwargs):
        
        filename = os.path.basename(self.object.file.name)

        # Try to guess the content type of the given file
        content_type, _ = mimetypes.guess_type(self.object.file.name)
        if not content_type:
            content_type = 'text/plain'

        response = HttpResponse(self.object.file, content_type=content_type)
        response['Content-Disposition'] = 'attachment; filename={}'.format(filename)

        return response
1357407
def _process_attachments(self, email):
        
        for a in email.attachments:
            if isinstance(a, MIMEBase):
                if not a.is_multipart():
                    obj = {
                        'filename': a.get_filename(),
                        'content_type': a.get_content_type(),
                    }
                    if a.get('content-transfer-encoding') == 'base64':
                        obj['content'] = a.get_payload()
                        obj['encoded'] = True
                    else:
                        obj['content'] = a.get_payload(decode=True)
                    yield obj
            else:
                yield {
                    'filename': a[0],
                    'content_type': a[2],
                    'content': a[1],
                }
723095
private function download()
    {
        header('Content-disposition: attachment; filename="'.$this->filename.'.'.$this->extension.'"');
        header('Content-type: application/octet-stream');
        
        readfile($this->filename.'.'.$this->extension);
    }