php-opencloud / openstack

PHP SDK for OpenStack clouds
Apache License 2.0
222 stars 152 forks source link

How to get a public URL using which I can view image in browser? #385

Closed divyeshccl closed 5 months ago

divyeshccl commented 5 months ago

I am using this to get the image

$object = $this->service->getContainer('test')->getObject('test/test.jpg')->download();

when I print $object I received this response. how to get the public URL?

GuzzleHttp\Psr7\Stream {
  -stream: stream resource
    wrapper_type: "PHP"
    stream_type: "TEMP"
    mode: "w+b"
    unread_bytes: 0
    seekable: true
    uri: "php://temp"
    options: []
  }
  -size: null
  -seekable: true
  -readable: true
  -writable: true
  -uri: "php://temp"
  -customMetadata: []
}
k0ka commented 5 months ago

You can get the content of the object by

$object = $this->service->getContainer('test')->getObject('test/test.jpg');
$stream = $object->download();
echo $stream->getContents();

You can get public URL via

$object = $this->service->getContainer('test')->getObject('test/test.jpg');
echo $object->getPublicUri();

But the file must be set public and some other settings must be set in Swift as far as I know.

divyeshccl commented 5 months ago

Thanks @k0ka