Retrieve the contents of a specific attachment (identified by filename).

        Writes data to file object, returns length of data written.
500028
def get_attachment(self, id, filename, file):
        
        data = self.get_attachment_data(id, filename)
        file.write(data)
        return len(data)
362364
public static String getFileContent(String filePath, long offset, int length) throws Exception {
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = getFileInputStream(filePath);
            return getFileContent(fileInputStream, offset, length);
        } finally {
            closeFileStream(fileInputStream, filePath);
        }
    }
414301
public Object getAttachment(String key) {
        return key == null ? null : attachments.get(key);
    }
1304650
def get_attachment_size(self, attachment):
        
        fsize = 0
        file = attachment.getAttachmentFile()
        if file:
            fsize = file.get_size()
        if fsize < 1024:
            fsize = '%s b' % fsize
        else:
            fsize = '%s Kb' % (fsize / 1024)
        return fsize
1206153
public Attachment getAttachmentMetaData(String assetId, String attachmentId) throws IOException, BadVersionException, RequestFailureException {
        // At the moment can only get all attachments
        Asset ass = getAsset(assetId);
        List<Attachment> allAttachments = ass.getAttachments();
        for (Attachment attachment : allAttachments) {
            if (attachmentId.equals(attachment.get_id())) {
                return attachment;
            }
        }

        // Didn't find it so just return null
        return null;
    }
223166
def fetch_to_file(self, filename):
        """"""
        self.filename = filename
        stream = self.client.get_iter_content(self.uri)
        content_type = self.client.response_headers['content-type']

        if content_type in _content_type_map:
            self.fileext = _content_type_map[content_type]
            self.filename = "%s.%s" % (self.filename, self.fileext)

        with open(self.filename, 'wb') as file_handle:
            for chunk in stream:
                file_handle.write(chunk)
87356
def file_contents(self, filename, binary=False):
        
        if binary:
            mode = 'rb'
        else:
            mode = 'r'
        try:
            with open(filename, mode) as f:
                return f.read()
        except (OSError, IOError) as e:
            raise FileReadError(str(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': '',
        }
101519
def file_size(self):
        
        stream = self.get_file_stream()
        stream.seek(0, os.SEEK_END)
        return stream.tell()
313836
def _file_details(filename):
    
    max_head, max_foot = _max_lengths()
    with open(filename, "rb") as fin:
        head = fin.read(max_head)
        try:
            fin.seek(-max_foot, os.SEEK_END)
        except IOError:
            fin.seek(0)
        foot = fin.read()
    return head, foot
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
805297
protected static PreparedAttachment prepareAttachment(String attachmentsDir,
                                                          AttachmentStreamFactory attachmentStreamFactory, Attachment attachment, long length, long encodedLength) throws AttachmentException {
        PreparedAttachment pa = new PreparedAttachment(attachment, attachmentsDir, length, attachmentStreamFactory);
        // check the length on disk is correct:
        // - plain encoding, length on disk is signalled by the "length" metadata property
        // - all other encodings, length on disk is signalled by the "encoded_length" metadata property
        if (pa.attachment.encoding == Attachment.Encoding.Plain) {
            if (pa.length != length) {
                throw new AttachmentNotSavedException(String.format("Actual length of %d does not equal expected length of %d", pa.length, length));
            }
        } else {
            if (pa.encodedLength != encodedLength) {
                throw new AttachmentNotSavedException(String.format("Actual encoded length of %d does not equal expected encoded length of %d", pa.encodedLength, pa.length));
            }
        }
        return pa;
    }
137956
def string(self, writesize=None):
        '''
        
        '''
        if not self.finished:
            self.finished = True
            return self.content
        return ''
41794
def find_attachment
      content_type_name = header[:content_type].filename rescue nil
      content_disp_name = header[:content_disposition].filename rescue nil
      content_loc_name = header[:content_location].location rescue nil

      if content_type && content_type_name
        filename = content_type_name
      elsif content_disposition && content_disp_name
        filename = content_disp_name
      elsif content_location && content_loc_name
        filename = content_loc_name
      elsif self.mime_type == "message/rfc822"
        filename = "#{rand(100000000)}.eml"
      else
        filename = nil
      end

      if filename
        # Normal decode
        filename = Mail::Encodings.decode_encode(filename, :decode) rescue filename
      end
      filename
    end
541045
def getAttachments(self):
        

        attachment_tag = ("rtc_cm:com.ibm.team.workitem.linktype."
                          "attachment.attachment")
        return (self.rtc_obj
                    ._get_paged_resources("Attachment",
                                          workitem_id=self.identifier,
                                          customized_attr=attachment_tag,
                                          page_size="10"))
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
465110
def to_email_attachment(self, filename, filedata, **kw):
        
        maintype = "application"
        subtype = "octet-stream"

        mime_type = mimetypes.guess_type(filename)[0]
        if mime_type is not None:
            maintype, subtype = mime_type.split("/")

        attachment = MIMEBase(maintype, subtype, **kw)
        attachment.set_payload(filedata)
        encoders.encode_base64(attachment)
        attachment.add_header("Content-Disposition",
                              "attachment; filename=%s" % filename)
        return attachment