Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating directories #14

Closed
rvmourik opened this issue Feb 22, 2016 · 5 comments
Closed

Creating directories #14

rvmourik opened this issue Feb 22, 2016 · 5 comments

Comments

@rvmourik
Copy link
Contributor

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.

@rvmourik
Copy link
Contributor Author

rvmourik commented Mar 9, 2016

Hi @frankdejonge ,

Is it possible to check the above issue and tell me if this is something that's gonna be integrated?

Thanks in advance.

Robbert

@frankdejonge
Copy link
Member

@rvmourik I'm not sure about this one. With AWS there's a "supported" way, with rackspace it's not. Which would introduce a "flysystem flavoured" way of interacting with rackspace, making it less transparent. Is there a need for creating the directory? Are you creating a file manager of some sorts?

@rvmourik
Copy link
Contributor Author

rvmourik commented Mar 9, 2016

Yes, it's going to be connected to a filemanager (elfinder for now).

But if you can take a look here https://developer.rackspace.com/docs/cloud-files/v1/developer-guide/ and you search for "application/directory", you'll get to the informatie how directories are "supported".

Isn't that their way of doing it and not a "flysystem flavoured" way like you suggested?

@frankdejonge
Copy link
Member

@rvmourik ah I see. A PR is welcome then 👍

@rvmourik
Copy link
Contributor Author

rvmourik commented Mar 9, 2016

@frankdejonge Going to try that, never done that before :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants