Uploads an attachment.

@param contentType
content type of the attachment.
@param content
attachment content stream.
@return attachment content.
@throws RedmineException
if something goes wrong.
@throws IOException
if input cannot be read.
485347
public Attachment uploadAttachment(String contentType, File content)
            throws RedmineException, IOException {
        try (InputStream is = new FileInputStream(content)) {
            return uploadAttachment(content.getName(), contentType, is, content.length());
        }
    }
992283
public void setContentType(String contentType) 
    {
        if (isCommitted() || contentType==null)
            return;
        
        int semi=contentType.indexOf(';');
        if (semi>0)
        {
            int charset0=contentType.indexOf("charset=",semi);
            if (charset0>0)
            {
                if (_outputState==WRITER_OUT)
                {
                    // need to strip charset= from params
                    int charset1=contentType.indexOf(' ',charset0);
                    
                    if ((charset0==semi+1 && charset1<0) ||
                        (charset0==semi+2 && charset1<0 && contentType.charAt(semi+1)==' ' ))
                        _httpResponse.setContentType(contentType.substring(0,semi));
                    else if (charset1<0)
                        _httpResponse.setContentType(contentType.substring(0, charset0).trim());
                    else
                        _httpResponse.setContentType(contentType.substring(0, charset0)+contentType.substring(charset1));
                }
                else
                {
                    _charEncodingSetInContentType=true;
                    _httpResponse.setContentType(contentType);
                }
            }
            else
                _httpResponse.setContentType(contentType);
        }
        else
            _httpResponse.setContentType(contentType);
        
        if (_locale!=null)
            setLocale(_locale);
    }
594986
public void setContentType(String type) {
		checkContentType(type);
		checkCommitted();
		String name = getCorrectHeaderName(ContentTypeHeader.NAME);
		try {
			Header h = SipFactoryImpl.headerFactory.createHeader(name, type);
			this.message
					.removeHeader(getCorrectHeaderName(ContentTypeHeader.NAME));
			this.message.addHeader(h);
		} catch (ParseException e) {
			logger.error("Error while setting content type header !!!", e);
		}

	}
610483
public void setContentType(String contentType) 
    {
        if (isCommitted())
            return;
        
        if (contentType==null)
        {
            _mimeType=null;
            _header.remove(HttpFields.__ContentType);
        }
        else
        {
            // Look for encoding in contentType
            int i0=contentType.indexOf(';');
            
            if (i0>0)
            {
                // Strip params off mimetype
                _mimeType=contentType.substring(0,i0).trim();
                
                // Look for charset
                int i1=contentType.indexOf("charset=",i0);
                if (i1>=0)
                {
                    i1+=8;
                    int i2 = contentType.indexOf(' ',i1);
                    _characterEncoding = (0<i2)
                    ? contentType.substring(i1,i2)
                                    : contentType.substring(i1);
                    _characterEncoding = QuotedStringTokenizer.unquote(_characterEncoding);
                }
                else // No encoding in the params.
                {
                    if (_characterEncoding!=null)
                        // Add any previously set encoding.
                        contentType+=";charset="+QuotedStringTokenizer.quote(_characterEncoding,";= ");
                }
            }
            else // No encoding and no other params
            {
                _mimeType=contentType;
                // Add any previously set encoding.
                if (_characterEncoding!=null)
                    contentType+=";charset="+QuotedStringTokenizer.quote(_characterEncoding,";= ");
            }
            
            _header.put(HttpFields.__ContentType,contentType);
        }
    }
506011
public void upload(final String uri, final File sourceFile, final String contentType)
            throws IOException, AppPlatformException {
        final String path = getPath(uri);
        final HttpPut request = (HttpPut) setupRequest(path, HttpPut.METHOD_NAME, null);
        request.setEntity(contentType == null ? new FileEntity(sourceFile) : new FileEntity(sourceFile, ContentType.parse(contentType)));
        performRequest(request);
    }
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
1066472
public MessageProtocol withContentType(String contentType) {
        return new MessageProtocol(Optional.ofNullable(contentType), charset, version);
    }
588121
static DeploymentContent of(final InputStream content) {
        final ByteArrayInputStream copiedContent = copy(content);
        return new DeploymentContent() {
            @Override
            void addContentToOperation(final OperationBuilder builder, final ModelNode op) {
                copiedContent.reset();
                final ModelNode contentNode = op.get(CONTENT);
                final ModelNode contentItem = contentNode.get(0);
                // The index is 0 based so use the input stream count before adding the input stream
                contentItem.get(ClientConstants.INPUT_STREAM_INDEX).set(builder.getInputStreamCount());
                builder.addInputStream(copiedContent);
            }

            @Override
            public String toString() {
                return String.format("%s(%s)", DeploymentContent.class.getName(), copiedContent);
            }
        };
    }
364286
public SoapServerFaultResponseActionBuilder attachment(String contentId, String contentType, Resource contentResource) {
        return attachment(contentId, contentType, contentResource, FileUtils.getDefaultCharset());
    }
989428
public static <T extends File> T createFile(final SecurityContext securityContext, final byte[] fileData, final String contentType, final Class<T> t)
		throws FrameworkException, IOException {

		return createFile(securityContext, fileData, contentType, t, null, true);

	}
1169500
public SoapServerFaultResponseActionBuilder attachment(String contentId, String contentType, Resource contentResource, Charset charset) {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId(contentId);
        attachment.setContentType(contentType);

        try {
            attachment.setContent(FileUtils.readToString(contentResource, charset));
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to read attachment resource", e);
        }

        getAction().getAttachments().add(attachment);

        return this;
    }
1173784
public function sendFile($file, $name=NULL, $contentType='application/octet-stream', $contentDisposition='attachment'){
        if($name == NULL){
            $name= basename($file);
        }
        header('Content-Description: File Transfer');
        header('Content-Type: '.$contentType);
        header('Content-Disposition: '.$contentDisposition.'; filename="'.$name.'"');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        readfile($file);        
    }
551066
public function addAttachmentFromData($name, $data, $mimeType = 'application/octet-stream', $contentId = null)
    {
        $this->_attachments[] = array(
            'name' => $name,
            'mimeType' => $mimeType,
            'data' => $data,
            'contentId' => $contentId
        );
    }
325378
def set_content(self, value: RequestContent, *,
                    content_type: str = None):
        '''
        
        '''
        assert self._attached_files is None, \
               'cannot set content because you already attached files.'
        guessed_content_type = 'application/octet-stream'
        if value is None:
            guessed_content_type = 'text/plain'
            self._content = b''
        elif isinstance(value, str):
            guessed_content_type = 'text/plain'
            self._content = value.encode('utf-8')
        else:
            guessed_content_type = 'application/octet-stream'
            self._content = value
        self.content_type = (content_type if content_type is not None
                             else guessed_content_type)
816198
public static Attachment fromTextInputStream( InputStream inputStream, MediaType mediaType ) throws IOException {
        return fromText( CharStreams.toString( new InputStreamReader( inputStream, mediaType.getCharset() ) ), mediaType );
    }
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)
682235
public InputStream doPost(byte[] postData, String contentType) {
        this.urlConnection.setDoOutput(true);
        if (contentType != null) this.urlConnection.setRequestProperty( "Content-type", contentType );

        OutputStream out = null;
        try {
            out = this.getOutputStream();
            if(out!=null)
            {
                out.write(postData);
                out.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(out!=null)
                try {
                    out.close();
                } catch (IOException e) {
                    //
                }
        }


        return (this.getInputStream());
    }