public static function toRavelryPostFile($value, Parameter $parameter)
    {
        if (is_string($value)) {
            $value = fopen($value, 'r');
        }

        if (!($value instanceof StreamInterface)) {
            $value = \GuzzleHttp\Stream\create($value);
        }

        if ($value instanceof MetadataStreamInterface) {
            $filename = $value->getMetadata('uri');
        }

        if (!$filename || substr($filename, 0, 6) === 'php://') {
            $filename = $parameter->getWireName();
        }

        return new PostFile(
            $parameter->getWireName(),
            $value,
            $filename,
            [
                'Content-Disposition' => sprintf(
                    'form-data; name="%s"; filename="%s"',
                    $parameter->getWireName(),
                    basename($filename)
                ),
            ]
        );
    }
public static function toRavelryPostFile($value, Parameter $parameter)
    {
        if (is_string($value)) {
            $value = fopen($value, 'r');
        }

        if (!($value instanceof StreamInterface)) {
            $value = \GuzzleHttp\Stream\create($value);
        }

        if ($value instanceof MetadataStreamInterface) {
            $filename = $value->getMetadata('uri');
        }

        if (!$filename || substr($filename, 0, 6) === 'php://') {
            $filename = $parameter->getWireName();
        }

        return new PostFile(
            $parameter->getWireName(),
            $value,
            $filename,
            [
                'Content-Disposition' => sprintf(
                    'form-data; name="%s"; filename="%s"',
                    $parameter->getWireName(),
                    basename($filename)
                ),
            ]
        );
    }
public static function toRavelryPostFile ( $ value , Parameter $ parameter ) { if ( is_string ( $ value ) ) { $ value = fopen ( $ value , 'r' ) ; } if ( ! ( $ value instanceof StreamInterface ) ) { $ value = \ GuzzleHttp \ Stream \ create ( $ value ) ; } if ( $ value instanceof MetadataStreamInterface ) { $ filename = $ value -> getMetadata ( 'uri' ) ; } if ( ! $ filename || substr ( $ filename , 0 , 6 ) === 'php://' ) { $ filename = $ parameter -> getWireName ( ) ; } return new PostFile ( $ parameter -> getWireName ( ) , $ value , $ filename , [ 'Content-Disposition' => sprintf ( 'form-data; name="%s"; filename="%s"' , $ parameter -> getWireName ( ) , basename ( $ filename ) ) , ] ) ; }
This is duplicating logic from `GuzzleHttp\Post\PostFile` in order to
patch odd API server behavior. It also makes sure the value is a proper
stream reference.

See http://www.ravelry.com/discuss/ravelry-api/2936052/1-25#5
This is duplicating logic from GuzzleHttp \ Post \ PostFile in order to patch odd API server behavior . It also makes sure the value is a proper stream reference .