Giter Site home page Giter Site logo

flysystem-rackspace's Introduction

Flysystem Adapter for Rackspace.

Author Build Status Coverage Status Quality Score Software License Packagist Version Total Downloads

Installation

composer require league/flysystem-rackspace

Usage

use OpenCloud\OpenStack;
use OpenCloud\Rackspace;
use League\Flysystem\Filesystem;
use League\Flysystem\Rackspace\RackspaceAdapter as Adapter;

$client = new Rackspace(Rackspace::UK_IDENTITY_ENDPOINT, array(
    'username' => ':username',
    'apiKey' => ':password',
));

$store = $client->objectStoreService('cloudFiles', 'LON');
$container = $store->getContainer('flysystem');

$filesystem = new Filesystem(new Adapter($container));

flysystem-rackspace's People

Contributors

ah017 avatar deefour avatar frankdejonge avatar grahamcampbell avatar jenkoian avatar rvmourik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flysystem-rackspace's Issues

Creating directories

Hi,

We're using the adapter to use an object store as our filesystem, but creating directories was not working. After investigating we got to the conclusion the createDir method only returns a array with the dirname.

Altough Rackspace doesn't officially supports the use of folders, there is a way of getting this to work. In order for directories to work you need to send two additional headers with the request.

Contents: None
Content-Type: application/directory

I've changed the createDir and normalizeObject to work with this solution.

createDir

public function createDir($dirname, Config $config)
    {
//        return ['path' => $dirname];
        $headers = [];

        if ($config->has('headers')) {
            $headers = $config->get('headers');
        }

        if (!key_exists('Contents', $headers)) {
            $headers['Contents'] = 'None';
        }

        if (!key_exists('Content-Type', $headers)) {
            $headers['Content-Type'] = 'application/directory';
        }

        $config->set('headers', $headers);

        return $this->write($dirname, '', $config);
    }

normalizeObject

protected function normalizeObject(DataObject $object)
    {
        $name = $object->getName();
        $name = $this->removePathPrefix($name);
        $mimetype = explode('; ', $object->getContentType());

        return [
            'type'      => ((in_array('application/directory', $mimetype)) ? 'dir' : 'file'),
            'dirname'   => Util::dirname($name),
            'path'      => $name,
            'timestamp' => strtotime($object->getLastModified()),
            'mimetype'  => reset($mimetype),
            'size'      => $object->getContentLength(),
        ];
    }

Is this something you'll be willing to integrate in the adapter, if so do you need a pull request (never done that before :-)) or can you manually use the above code adjustments.

Large Uploads

Rackspace uses

    $transfer = $container->setupObjectTransfer(array(
        'name' => 'video.mov',
        'path' => '/home/jamie/video.mov',
        'metadata' => array(
            'Author' => 'Jamie'
        ),
        'concurrency' => 4,
        'partSize'    => 1.5 * Size::GB
    ));

    $transfer->upload();

Instance of Closure given

Hi, since the last release I got this:

Type error: Argument 1 passed to LeagueFlysystemRackspaceRackspaceAdapter_XXXXX::__construct() must be an instance of OpenCloud\ObjectStore\Resource\Container, instance of Closure given, called in /var/www/demophonie/app/cache/dev/appDevDebugProjectContainer.php on line 6614

I tried alone to debug it but without results.
Have you any idea ?

I'm under Symfomy 2.8.2 and PHP7.0.2. From my point of view, issue is linked to dependency injection.

Thanks.

Is it alive?

Hello.
The last commit was in 2016, the last commit of dependency rackspace/php-opencloud was in 2017, dependency guzzle/guzzle was abandoned since 2015.
Is this package still maintained??

How to use the snet endpoint?

How can I use the rackspace servicenet endpoint for faster connections, sine my servers are on rackspace datacenter

Thanks!

Package guzzle/guzzle is abandoned

Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.

Composer spits out this warning in every single composer command I use... Perhaps consider an update within this library?

readStream needs to be rewound before using

I've just spotted an inconsistency between the Local adapter and the Rackspace one:

$localFilesystem = new Filesystem(new Local('/path/to/dir'));
$localFilesystem->write('some/file', 'Hello');
$localStream = $localFilesystem->readStream('some/file');

echo stream_get_contents($localStream); // outputs Hello

$rackspaceFilesystem = new Filesystem(new RackspaceAdapter($container));
$rackspaceFilesystem->write('some/file', 'Hello');
$rackspaceStream = $rackspaceFilesystem->readStream('some/file');

echo stream_get_contents($rackspaceStream); // outputs an empty string

I think the stream should always be at the beginning of the file, or it's difficult to just change the adapter and get the same result.

cloudvps

Hi,

openstack v1.0 doesnt work on this package.

Get object URL

I tried to get a URL of a object, and I did not find any other way then making "getObject" method public and then call "$disk->getDriver()->getAdapter()->getObject('uploads/file.txt')->getUrl()"
Is there any other way, or implementing "getObjectUrl" method would be a good solution?

PHP Warning: fclose(): xx is not a valid stream resource

I was making use of the Rackspace adapter via flysytsem .

The code is as below .

$flysystem = new Filesystem(new RackspaceAdapter($container));
$fp = fopen($file, 'r+');
if ($fp) {
    $flysystem->writeStream($destination, $fp);
    fclose($fp);
}

I noticed when trying to close it says not a resource.

PHP Warning: fclose(): xx is not a valid stream resource in ...

Wonder whether flysystem at some point is automatically closing the same ?

Good thing is it is sending the data to the Cloud. So the file is already present on both local and server :) .

Seems not to work with PHP8 - Guzzle issue?

Instantiating Flysystem/Rackspace fails with PHP8. I've had this working with PHP7.4 for at least a year or so.

On PHP8, we get:

Deprecated: Required parameter $archive follows optional parameter $path in /var/www/html/includes/vendor/rackspace/php-opencloud/lib/OpenCloud/ObjectStore/Service.php on line 167
PHP Fatal error:  Uncaught Guzzle\Common\Exception\InvalidArgumentException: Invalid handle provided in /var/www/html/includes/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlHandle.php:237
Stack trace:
#0 /var/www/html/includes/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlHandle.php(223): Guzzle\Http\Curl\CurlHandle->__construct()
... and so on

Any fix for this?

readStream() returns empty string

So I am using Rackspace with my Symfony2 project,
The problem occurs when I want to read from stream:

$filesystem = $this->container->get('oneup_flysystem.XXXX_filesystem');
// Retrieve a read-stream
$stream = $filesystem->readStream('63335b4af21bf2f76145e21b1130570d2356b274.jpg');
$contents = stream_get_contents($stream);
if(is_resource($stream))
{
      fclose($stream);
}
var_dump($contents);

The file is there, the $contents is shown as empty string.
When I change readStream() to read(), it dumps all the data of the jpg file, but no data with readStream().
Any idea why?

PS: As per documentation in php.net, if stream_get_contents fails it will return FALSE not empty string.
Also note that writeStream() works just fine...

Expired tokens in long running tasks

Hello,

We're using this wonderful adapter in our workers dispatching queued jobs from different Laravel events.

Lately we're seeing errors in some of those workloads when trying to upload files into the Cloudfiles bucket, those errors come and go, and after talking to the Rackspace team seems there might be some problem with the token expiration.

Rackspace is suggesting to call $client->authenticate() that would refresh the expired token for a new one, but it might be overkill to reauthenticate every single time.

Did you guys got any similar reports about expired tokens in long-lived worker processes ? Any clue to get over it ?

Here's the error trace:

Guzzle\Http\Exception\ClientErrorResponseException: Client error response
[status code] 401
[reason phrase] Unauthorized
[url] https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_..../user/123456 in /home/worker/.../vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php:43
Stack trace:
#0 /home/worker/.../vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response))
...
#16 /home/worker.../vendor/league/flysystem-rackspace/src/RackspaceAdapter.php(93): OpenCloud\ObjectStore\Resource\Container->uploadObject('user/4564_1...', '\xFF\xD8\xFF
.....

Thanks!

Deleting Files

The rackspace adapter now has a deleteObject method (see rackspace/php-opencloud#651), instead of having to download the object to delete it. Could this be added to the adapter?

I can send a PR if I get time this week.

URL Encode filenames

It's mentioned briefly in the docs for OpenCloud that file names should be URL encoded if they're non-standard. Should the Rackspace adapter be handling this, or should I ensure my filenames are URLEncoded before passing them down the chain?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.