Create a stub attachment that has lazy loading capabilities.

@param string $contentType
@param int    $length
@param int    $revPos
@param Client $httpClient
@param string $path

@return Attachment
484299
public static function createStub($contentType, $length, $revPos, Client $httpClient, $path)
    {
        return new self(null, null, $contentType, $length, $revPos, $httpClient, $path);
    }
615848
public static function create(
        $content,
        $content_type = null,
        $status = ServiceResponseInterface::HTTP_OK,
        $headers = []
    ) {
        return new ServiceResponse($content, $content_type, $status, $headers);
    }
289953
public function uploadPartToAmazon(
        $filePath,
        $uploadEndpoint,
        $uploadRequestInfo,
        $chunkNumber,
        $chunk,
        $numberOfChunks
    ) {
        $finalKey = sprintf("%s/p%d", $uploadRequestInfo['multipart_params']['key'], $chunkNumber);
        $formData = [
            self::getFormDataParams('x-amz-credential', $uploadRequestInfo['multipart_params']['x-amz-credential']),
            self::getFormDataParams('X-Amz-Signature', $uploadRequestInfo['multipart_params']['X-Amz-Signature']),
            self::getFormDataParams('x-amz-algorithm', $uploadRequestInfo['multipart_params']['x-amz-algorithm']),
            self::getFormDataParams('x-amz-date', $uploadRequestInfo['multipart_params']['x-amz-date']),
            self::getFormDataParams('Policy', $uploadRequestInfo['multipart_params']['Policy']),
            self::getFormDataParams('key', $finalKey),
            self::getFormDataParams('acl', $uploadRequestInfo['multipart_params']['acl']),
            self::getFormDataParams('success_action_status',
                $uploadRequestInfo['multipart_params']['success_action_status']),
            self::getFormDataParams('Content-Type', $uploadRequestInfo['multipart_params']['Content-Type']),
            self::getFormDataParams('name', $filePath),
            self::getFormDataParams('chunk', $chunkNumber),
            self::getFormDataParams('chunks', $numberOfChunks),
            self::getFormDataParams('Filename', $finalKey),
            self::getFormDataParams('file', $chunk)
        ];

        $stack = HandlerStack::create(new CurlHandler());
        $oauthRequestClient = new Client([
            'base_uri' => $uploadEndpoint,
            'handler' => $stack,
        ]);

        return $oauthRequestClient->postAsync($uploadEndpoint, ['multipart' => $formData])
            ->then(
                function (ResponseInterface $response) {
                    return json_decode($response->getBody(), true);
                }
            );
    }
942447
public static function create($content = null, $contentType = 'text/plain')
    {
        $instance = new static();

        $instance->content = $content;
        $instance->contentType = $contentType;

        return $instance;
    }
1075768
public function addAttachmentFromFile($name, $path, $mimeType = 'application/octet-stream', $contentId = null)
    {
        if (file_exists($path) && is_file($path) && is_readable($path)) {
            $this->addAttachmentFromData($name, file_get_contents($path), $mimeType, $contentId);
        }
    }
453176
public static function file($path, $type = null)
    {
        $response = new self(
            Status::OK,
            new PhpStream($path, 'rb')
        );
        if (isset($type)) {
            $response->setHeader('Content-Type', $type);
        }
        return $response;
    }
1126078
public function uploadUrl($key, $acl, $mimeType = null, $cacheControl = null, $expires = null) {
		try {
			$optionsData = [
				'ACL' => $acl,
				'Bucket' => $this->bucket,
				'ContentType' => $mimeType,
				'Key' => $key
			];

			if(!empty($cacheControl)) {
				$optionsData[] = ['CacheControl' => $cacheControl];
			}

			if(!empty($expires)) {
				$optionsData[] = ['Expires' => $expires];
			}

			$putCommand = $this->client->getCommand('PutObject',$optionsData);
			$request = $this->client->createPresignedRequest($putCommand, '+20 minutes');
			$signedUrl = (string)$request->getUri();

			return new OtherS3UploadInfo($key,$signedUrl,$acl);
		}
		catch(AwsException $ex) {
			Logger::error('S3 Generate File Upload URL Error', ['exception' => $ex->getMessage()]);
			throw new StorageException($ex->getMessage(), $ex->getCode(), $ex);
		}
	}
672129
public function asset($path, $contentType = 'null', $fullURL = true)
    {
        if (!$fullURL) {
            return base_path(__DIR__.'/../Assets/'.$path);
        }

        return url($this->backendRoute.'/asset/'.CryptoServiceFacade::url_encode($path).'/'.CryptoServiceFacade::url_encode($contentType));
    }
1373377
private void setMultipart(String contentType) {
        String[] dataBoundary = HttpPostRequestDecoder.getMultipartDataBoundary(contentType);
        if (dataBoundary != null) {
            multipartDataBoundary = dataBoundary[0];
            if (dataBoundary.length > 1 && dataBoundary[1] != null) {
                charset = Charset.forName(dataBoundary[1]);
            }
        } else {
            multipartDataBoundary = null;
        }
        currentStatus = MultiPartStatus.HEADERDELIMITER;
    }
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());
        }
    }
192532
public static function newDocumentPHP($markup = null, $contentType = "text/html") 
    {
        // TODO pass charset to phpToMarkup if possible (use DOMDocumentWrapper function)
        $markup = phpQuery::phpToMarkup($markup, self::$defaultCharset);
        return self::newDocument($markup, $contentType);
    }
411205
private void rawCreateFolder( CPath path )
            throws CStorageException
    {
        CResponse response = null;
        try {
            String url = getObjectUrl( path );
            HttpPut request = new HttpPut( url );
            request.addHeader( "Content-Type", CONTENT_TYPE_DIRECTORY );

            RequestInvoker<CResponse> ri = getApiRequestInvoker( request, path );
            response = retryStrategy.invokeRetry( ri );

        } finally {
            PcsUtils.closeQuietly( response );
        }
    }
532281
public function download($fileName, $contentType, $contents)
    {
        $body = $this->builder->messages()->stringStream($contents);
        return $this->downloadResponse($fileName, $contentType, $body);
    }
13165
public function send(string $method, Client $httpClient, array $path = []): DorcasResponse
    {
        $this->prefillHeader();
        $this->prefillBody();
        if (strtolower($method) !== 'get') {
            # we don't validate GEt requests
            $this->validate();
        }
        $uri = static::getRequestUrl($path);
        $url = $uri->getScheme() . '://' . $uri->getAuthority() . $uri->getPath();
        # set the URL
        try {
            $options = [];
            # the request data
            if (!empty($this->headers)) {
                $options[RequestOptions::HEADERS] = $this->headers;
            }
            if (!empty($uri->getQuery())) {
                # some query parameters are present in the URL
                $options[RequestOptions::QUERY] = parse_query_parameters($uri->getQuery());
            }
            if (strtolower($method) !== 'get') {
                # not a get request
                if (!empty($this->multipart)) {
                    # check if we have some multipart data first
                    foreach ($this->body as $key => $value) {
                        # add the requested body params to the multipart data
                        $this->multipart[] = ['name' => $key, 'contents' => $value];
                    }
                    $options[RequestOptions::MULTIPART] = $this->multipart;

                } elseif (static::isJsonRequest() && !empty($this->body)) {
                    # a JSON request
                    $options[RequestOptions::JSON] = $this->body;

                } elseif (!empty($this->body)) {
                    # we switch to an application/www-form-urlencoded type
                    $options[RequestOptions::FORM_PARAMS] = $this->body;
                }
            }
            $response = $httpClient->request($method, $url, $options);
            return new DorcasResponse((string) $response->getBody());

        } catch (BadResponseException $e) {
            // in the case of a failure, let's know the status
            return new DorcasResponse((string) $e->getResponse()->getBody(), $e->getResponse()->getStatusCode(), $e->getRequest());

        } catch (ConnectException $e) {
            return new DorcasResponse('{"status": "error", "data": "'.$e->getMessage().'"}', 0);
        }
    }
299263
protected function makeRequest($method, $uri, array $data = NULL, $contentType = Http::CONTENT_JSON)
	{
		// Invoke events
		$this->trigger('onRequest', [$method, $uri, $data]);

		// Verify that client is authenticated
		if (!$this->client->hasToken()) {
			// Do authorization
			$this->doAuthorization();
		}

		$request = new Request();

		// Set-up URL
		$request->setUrl(Gateway::getFullApiUrl($uri));

		// Set-up headers
		$headers = [
			'Accept' => 'application/json',
			'Authorization' => 'Bearer ' . $this->client->getToken()->accessToken,
			'Content-Type' => $contentType,
		];
		$request->setHeaders($headers);

		// Set-up opts
		$request->setOpts($this->options);

		// Set-up method
		switch ($method) {

			// GET =========================================
			case HttpClient::METHOD_GET:
				$request->appendOpts([
					CURLOPT_HTTPGET => TRUE,
				]);

				break;

			// POST ========================================
			case HttpClient::METHOD_POST:
				$request->appendOpts([
					CURLOPT_POST => TRUE,
					CURLOPT_POSTFIELDS => $contentType === Http::CONTENT_FORM ? http_build_query($data) : json_encode($data),
				]);

				break;

			default:
				throw new InvalidStateException('Unsupported http method');
		}

		return $this->client->call($request);
	}
1290411
public static function attachment($path_or_data = null, $filename = null, $contentType = null) {
        $from_path = realpath($path_or_data);
        if ($from_path) {
            $attachment = Swift_Attachment::fromPath($path_or_data, $contentType);
            $attachment->setFilename($filename);
        } else {
            $attachment = Swift_Attachment::newInstance($path_or_data, $filename, $contentType);
        }
        return $attachment;
    }
83059
public function addEmbeddedFile(string $file, string $content = null, string $contentType = null): MimePart
    {
        return $this->inlines[$file] = $this->createAttachment($file, $content, $contentType, 'inline')
            ->setHeader('Content-ID', $this->getRandomId());
    }