Git Product home page Git Product logo

flysystem-bundle's Introduction

flysystem-bundle

Packagist Version Software license

flysystem-bundle is a Symfony bundle integrating the Flysystem library into Symfony applications.

It provides an efficient abstraction for the filesystem in order to change the storage backend depending on the execution environment (local files in development, cloud storage in production and memory in tests).

Note: you are reading the documentation for flysystem-bundle 3.0, which relies on Flysystem 3.
If you use Flysystem 1.x, use flysystem-bundle 1.x.
If you use Flysystem 2.x, use flysystem-bundle 2.x.
Read the Upgrade guide to learn how to upgrade.

Installation

flysystem-bundle 3.x requires PHP 8.0+ and Symfony 5.4+.

If you need support for a lower PHP/Symfony version, consider using flysystem-bundle 2.x which support Flysystem 3.x and older PHP/Symfony versions.

You can install the bundle using Symfony Flex:

composer require league/flysystem-bundle

Basic usage

The default configuration file created by Symfony Flex provides enough configuration to use Flysystem in your application as soon as you install the bundle:

# config/packages/flysystem.yaml

flysystem:
    storages:
        default.storage:
            adapter: 'local'
            options:
                directory: '%kernel.project_dir%/var/storage/default'

This configuration defines a single storage service (default.storage) based on the local adapter and configured to use the %kernel.project_dir%/var/storage/default directory.

For each storage defined under flysystem.storages, an associated service is created using the name you provide (in this case, a service default.storage will be created). The bundle also creates a named alias for each of these services.

This means you have two way of using the defined storages:

  • either using autowiring, by typehinting against the FilesystemOperator and using the variable name matching one of your storages:

    use League\Flysystem\FilesystemOperator;
    
    class MyService
    {
        private FilesystemOperator $storage;
        
        // The variable name $defaultStorage matters: it needs to be the camelized version
        // of the name of your storage. 
        public function __construct(FilesystemOperator $defaultStorage)
        {
            $this->storage = $defaultStorage;
        }
        
        // ...
    }

    The same goes for controllers:

    use League\Flysystem\FilesystemOperator;
    
    class MyController
    {
        // The variable name $defaultStorage matters: it needs to be the camelized version
        // of the name of your storage. 
        public function index(FilesystemOperator $defaultStorage)
        {
            // ...
        }
    }
  • or using manual injection, by injecting the service named default.storage inside your services.

Once you have a FilesystemOperator, you can call methods from the Filesystem API to interact with your storage.

Full documentation

  1. Getting started
  2. Cloud storage providers: AsyncAws S3, AWS SDK S3, Azure, Google Cloud Storage, DigitalOcean Spaces, Scaleway Object Storage
  3. Interacting with FTP and SFTP servers
  4. Using a lazy adapter to switch storage backend using an environment variable
  5. Creating a custom adapter
  6. MongoDB GridFS

Security Issues

If you discover a security vulnerability within the bundle, please follow our disclosure procedure.

Backward Compatibility promise

This library follows the same Backward Compatibility promise as the Symfony framework: https://symfony.com/doc/current/contributing/code/bc.html

Note: many classes in this bundle are either marked @final or @internal. @internal classes are excluded from any Backward Compatibility promise (you should not use them in your code) whereas @final classes can be used but should not be extended (use composition instead).

flysystem-bundle's People

Contributors

airnzspijkn avatar broiniac avatar gromnan avatar jmsche avatar johndodev avatar johnstoncode avatar jonag avatar julian-louis avatar ker0x avatar kevinpapst avatar lustmored avatar maxhelias avatar meyron avatar michealmouner avatar nclshart avatar norkunas avatar nspyke avatar ntomka avatar nyholm avatar oskarstark avatar pgrimaud avatar qdequippe avatar radiergummi avatar rogamoore avatar rubc avatar syffer avatar tacman avatar tgalopin avatar tofandel avatar vincentlanglet 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  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  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-bundle's Issues

Wrong URI with aws/aws-sdk-php v3.175.0

Hi,

I updated my project dependencies and now it is using aws/aws-sdk-php v3.175.0.
Before that version, the URI of the S3 instance was correct (let say https://s3.cloud.app), but with this new version, the URL that is hitted is bucket_name.https://s3.cloud.app which is wrong.

From what I understand, this is caused by this change and the new behaviour of src/S3/BucketEndpointArnMiddleware.php.

Can you help me fixing this bug. I think this is just something that we need to configure, but I cannot find how from the documentation.
The bundle configuration is as follow:

flysystem:
    storages:
        default.storage:
            adapter: 'aws'
            options:
                client: 's3_client'
                bucket: "%env(S3_BUCKET)%"

Many thanks.
Regards.

Got this stream from `flysystem-bundle` without seekable opportunity

I use flysystem-bundle products from the same company thephpleague. I got this stream from flysystem-bundle without seekable opportunity

flysystem:
  storages:
    reaources.storage:
      adapter: 'aws'
      options:
        client: 'Aws\S3\S3Client' # The service ID of the Aws\S3\S3Client instance
        bucket: 'minimoj-consumer'
        prefix: 'minimoj'

services:
  Aws\S3\S3Client:
    arguments:
      - endpoint: '%env(S3_END_POINT)%'
        version: 'latest'
        region: 'ams3'
        use_path_style_endpoint: true
        credentials:
          key: '%env(S3_STORAGE_KEY)%'
          secret: '%env(S3_STORAGE_SECRET)%'

then

use Keven\Flysystem\Concatenate\Append;
use Keven\Flysystem\Concatenate\Concatenate;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\Util;

class DigitalOceanStorage
{
    private $storage;

    // The variable name $defaultStorage matters: it needs to be the camelized version
    // of the name of your storage.
    public function __construct(FilesystemInterface $reaourcesStorage)
    {
        $reaourcesStorage->addPlugin(new Append());
        $this->storage = $reaourcesStorage;
    }

    /**
     * @return FilesystemInterface
     */
    public function getStorage(): FilesystemInterface
    {
        return $this->storage;
    }

and in my service

    /**
     * @var DigitalOceanStorage
     */
    private $do;


           .....


            $readStream = $this->do->getStorage()->readStream($filePath);

and this is stream not seekable

result = {array} [11]
 crypto = {array} [4]
 timed_out = false
 blocked = true
 eof = false
 wrapper_data = {array} [12]
 wrapper_type = "http"
 stream_type = "tcp_socket/ssl"
 mode = "r"
 unread_bytes = {int} 7715
 seekable = false
 uri = "https://minimoj-consumer.ams3.digitaloceanspaces.com/minimoj-consumer/minimoj/download_files/adrecord/gus_textil/20200909163429.csv"

How to make my stream seekable ?
from what this is dependencies, rom digital ocean space ?

FTP adapter configuration builder does not expose all options

The FTP Adapter definition builder does not expose all options provided by the underlying FTP connection options:

FTP Adapter Option Builder Option
host host
root root
username username
password password
port port
ssl ssl
timeout timeout
utf8 utf8
passive passive
transferMode ⚠️ Missing
systemType ⚠️ Missing
timestampsOnUnixListingsEnabled ⚠️ Missing
ignorePassiveAddress ignore_passive_address
recurseManually ⚠️ Missing

I don't know why this is, but I desperately need timestampsOnUnixListingsEnabled for a project of mine. If there's no reason for the options to be missing, I'd provide a PR to add support for the missing options.

Cannot build adapter

Hello! I'm having trouble building any adapter that uses env variables.

I have this config in flysystem.yaml

flysystem:
    storages:
        default.storage:
            adapter: 'gcloud'
            options:
                bucket: '%env(GCLOUD_STORAGE_BUCKET)%'
                client: '%env(GCLOUD_CLIENT_ID)%'

I get an error:

Incompatible use of dynamic environment variables "GCLOUD_CLIENT_ID" found in parameters.

I also tried with parameters still no luck

parameters:
    gcloud_storage_bucket: '%env(GCLOUD_STORAGE_BUCKET)%'
    gcloud_client_id: '%env(GCLOUD_CLIENT_ID)%'
flysystem:
    storages:
        default.storage:
            adapter: 'gcloud'
            options:
                bucket: '%gcloud_storage_bucket%'
                client: '%gcloud_client_id%'

Support league/flysystem-aws-s3-v2

To use the S3 compatible Exoscale instead of AWS S3 we need to use league/flysystem-aws-s3-v2 instead of league/flysystem-aws-s3-v2.

No version of your bundle does support v2 but only v3 - or is that wrong? Do you plan to support it or do we have to switch to oneup/flysystem-bundle?

Default visibility public ACL for object created in a bucket

Hello,

Objects created via VichUploaderBundle does not allow to change the default visibility, so all objects are created with a private ACL (default).

I remember that 1UpFlysystemBundle has an option for its bundle to set the default visibility for created object; How to achieve that for this bundle ?

I tried to pass extra options for the storage client, but the visibility option doesn't exist:

flysystem:
    storages:
        user.storage.source:
            adapter: 'asyncaws'
            options:
                client: 'async_aws.client.s3'
                bucket: '%env(S3_BUCKET_NAME)%'
                prefix: '/users'
                options:
                    visibility: public-read    <--- doesn't exist :'D 

Reference: dustin10/VichUploaderBundle#1149

Cannot autowire argument $filesystemOperator

Symfony 6.0

Php 8.1

Error

Cannot autowire argument $filesystemOperator of "App\Controller\Api\EmailTemplateController()": it references interface "League\Flysystem\FilesystemOperator" but no such service exists. Available autowiring aliases for this interface are: "$defaultStorage".

Controller

public function __invoke(
   \League\Flysystem\FilesystemOperator $filesystemOperator
): JsonResponse {

Autowiring enabled

Basename not working

Hello so i try to install and use this bundel

This is my controleur :

<?php

namespace App\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Events\BienvenueUtilisateur;
use League\Flysystem\FilesystemOperator;


class HomeController extends AbstractController
{
    /**
     * @Route("/", name="index")
     * @return Response
     * 
     */
    public function index(Request $request,FilesystemOperator $defaultStorage): Response
    {
        $path = "";
        $recursive = FALSE;

        $contents = $defaultStorage->listContents($path, $recursive);

        foreach ($contents as $object) {
            echo $object['basename'].' is located at '.$object['path'].' and is a '.$object['type'];
            //echo ' is located at '.$object['path'].' and is a '.$object['type'];
        }
        


        return $this->render( "index.html.twig",[
            "firstname" => "Zozor..."
        ]

        );
    }

    
    
}

`

and i got this error :

Notice: Undefined property: League\Flysystem\FileAttributes::$basename

image

i follow this how to :
https://flysystem.thephpleague.com/v1/docs/usage/filesystem-api/

do u know what is wrong please ?

Registering the bundle ("There is no extension able to load")

Hello guys,

Thanks for your work. I found your various packages very helpful. I'm going to integrate the flysystem for S3 cloud in my Symfony4 application. And after quick research and reading your installation documentation I did steps like those:

  1. composer require league/flysystem-bundle
  2. composer require league/flysystem-aws-s3-v3
  3. Added content into config/packages/flysystem.yaml
    (hope steps are fine)

And I got the error: There is no extension able to load the configuration for "flysystem" (in config/packages/flysystem.yaml).

I understand, it because I didn't register your bundle (didn't update AppKernel.php or list of bundles). But I didn't find anything about BundleInterface in the vendor/league directory. What should I register? I'm just going through steps from your documentation. It seems something is missed there.

So, my questions:

  1. Are my steps correct?
  2. Should I use both packages (flysystem-bundle and flysystem-aws-s3-v3)?
  3. Should I add OneupFlysystemBundle package too?
  4. Should I register a bundle in my AppKernel.php file and how?

Thanks in advance.

LiipImagine bundle with AWS SDK S3 Not working online (Heroku server)

I managed to operate the bundle locally but online I can not display the images.
When I call the image directly I recover this error message:
AWS HTTP error: Client error: PUT https://s3-image-snowtrick.s3.eu-west-3.amazonaws.com/snowtrick-image/mute-605308ce4f198.jpg` resulted in a 400 Bad Request response: AuthorizationHeaderMalformedThe authorization header (truncated...) AuthorizationHeaderMalformed (client): The authorization header is malformed; a non-empty Access Key (AKID) must be provided in the credential. - `
You have an idea of why I am asked for an akid while in local it works without. I specify that I provided the public and private keys of my AWS S3 account via variables of environments.

[question] access S3Client object from services from within symfony

I'm using S3 (minio) as my data storage adapter. I set up the server config in the yaml file, but I need the S3Client object to get temporary pre-signed URLs to files. Is there a way I can get the S3Client used by flysystem to reuse its configuration? On a related note, is there a way to get tempraroy pre-signed URLs from S3 using flysystem directly?

config/packages/flysystem.yaml

flysystem:
    storages:
        default.storage:
            adapter: 'local'
            options:
                directory: '%kernel.project_dir%/public/media'

        images.storage:
            adapter: 'aws'
            options:
                client: 'Aws\S3\S3Client'
                bucket: 'images'
                
services:
    Aws\S3\S3Client:
        arguments:
            - endpoint: 'http://minio:9000'
              version: 'latest'
              region: 'us-east-1'
              use_path_style_endpoint: true
              credentials:
                  key: '%env(S3_STORAGE_KEY)%'
                  secret: '%env(S3_STORAGE_SECRET)%'

src/EventSubscriber/ResolveMediaObjectContentUrlSubscriber.php

public function onPreSerialize(ViewEvent $event): void
{
...
$this->s3 = new S3Client([
            'endpoint' => 'http://localhost:9000',
            'version' => 'latest',
            'region'  => 'us-east-1',
            'use_path_style_endpoint' => true,
            'credentials' => [
                'key'    =>  $_ENV["S3_STORAGE_KEY"],
                'secret' => $_ENV["S3_STORAGE_SECRET"],
            ],
        ]);

$command = $this->s3->getCommand('GetObject', [
    'Bucket' => 'images',
    'Key'    => $mediaObject->file
]);
$preSignedRequest = $this->s3->createPresignedRequest($command, '+10 minutes');
$preSignedUrl =  (string)  $preSignedRequest->getUri();
...
}

AsyncAws S3 SSE-C Encryption

Hey,

is it possible to use SSE-C encryption (https://docs.aws.amazon.com/AmazonS3/latest/userguide/specifying-s3-c-encryption.html) with flysystem and AsyncAws S3?
I know async s3 has options to support it but I can't figure out if it's possible to use in conjunkture with flysystem/this bundle

Edit: It's in the available options list in the flysystem adapter https://github.com/thephpleague/flysystem-async-aws-s3/blob/512815b28d08fa5753644e7f76d0bfbf23d453cd/AsyncAwsS3Adapter.php#L53 so the only question would be how to actually set those

Failure connecting using SFTP adapter with private key

Hello,
I am trying to store files using the SFTP adapter.
Everything works great as long I am using password authentication.
But when using a private key I get the error message: "Could not login with username: xxx, host: yyy".

After doing a bit of research in the source code I think I might have found the problem:
According to the SFTP adapters documentation (https://flysystem.thephpleague.com/docs/adapter/sftp/) the private key option is called "privateKey". However in the bundle configuration I am forced to use "private_key" and as far as I can see this option is given to the adapter directly. I believe this results in no private key being passed.

Ability to add plugins

Hello!
It would be great to add ability to add plugins for storages with autoconfigure \League\Flysystem\PluginInterface interface

FilesystemOperator side effect

I'm injecting a private readonly FilesystemOperator $localStorage into one of my classes; it is configured to use a path not available on my local machine, but within a Docker container. This class is then used in a custom introspection command (showing the current pipeline configuration), which I intended to run on the local machine.

As the filesystem operator is injected into the class, and the class is in turn injected into my command instance, the operator will be instantiated, too. Unexpectedly, though, this causes the mount path to be validated, yielding an exception:

In UnableToCreateDirectory.php line 20:
                                                                            
  Unable to create a directory at /opt/storage. mkdir(): Permission denied  

I would have expected this check upon the first filesystem operation, not sooner, that is: I would strongly expect library code to not have any side effects in their constructor - just as I would never expect a database class to attempt to connect within its constructor.

I'm not quite sure yet why exactly this happens, will have to dig deeper into the code, but this feels like a bug to me. What's the rationale behind executing runtime sanity checks in the constructor?

Release changes from 1.x branch

Would it be possible to release a new version from 1.x branch, please? There are more unreleased changes, but the most important is #64, which makes the bundle compatible with async-aws/flysystem-s3 v1.0. Thanks!

Please add default visibility option for directories

Local adapter creates only private disrectories :(

->addArgument($options['permissions'])

At this line, you can add a second argument for directories visibility rules.
Link on factory method:
https://github.com/thephpleague/flysystem/blob/7cbbb7222e8d8a34e71273d243dfcf383ed6779f/src/UnixVisibility/PortableVisibilityConverter.php#L99

Consider this improvement suggestion

Problem installing flysystem-aws-s3-v3 versioning

composer require league/flysystem-bundle

works, then to use DO spaces, I need to run:
composer require league/flysystem-aws-s3-v3

But it returns a number of version errors:

 Problem 1
    - league/flysystem-aws-s3-v3[2.0.0, ..., 2.x-dev] require league/flysystem ^2.0.0 -> found league/flysystem[2.0.0-alpha.1, ..., 2.x-dev] but the package is fixed to 1.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - league/flysystem-aws-s3-v3[2.0.0-alpha.1, ..., 2.0.0-alpha.2] require league/flysystem 2.0.0-alpha.1 -> found league/flysystem[2.0.0-alpha.1] but the package is fixed to 1.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - league/flysystem-aws-s3-v3[2.0.0-alpha.4, ..., 2.0.0-beta.1] require league/flysystem 2.0.0-alpha.3 -> found league/flysystem[2.0.0-alpha.3] but the package is fixed to 1.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - league/flysystem-aws-s3-v3[2.0.0-beta.2, ..., 2.0.0-beta.3] require league/flysystem ^2.0.0-beta.1 -> found league/flysystem[2.0.0-beta.1, ..., 2.x-dev] but the package is fixed to 1.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - league/flysystem-aws-s3-v3 2.0.0-RC1 requires league/flysystem ^2.0.0-RC1 -> found league/flysystem[2.0.0-RC1, ..., 2.x-dev] but the package is fixed to 1.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires league/flysystem-aws-s3-v3 ^2.0 -> satisfiable by league/flysystem-aws-s3-v3[2.0.0-alpha.1, ..., 2.x-dev].


Incompatible use of dynamic environment variables "int:FTP_PORT"

(1/2) InvalidOptionsException
The option "port" with value "%env(int:FTP_PORT)%" is expected to be of type "int", but is of type "string".
(2/2) EnvParameterException
Incompatible use of dynamic environment variables "int:FTP_PORT" found in parameters.

.env
FTP_PORT=221

flysystem.yaml

flysystem:
    storages:
        backup.storage:
            adapter: 'ftp'
            options:
                host: 'ftp.example.com'
                username: 'username'
                password: 'password'
                port: '%env(int:FTP_PORT)%'
                root: '/path/to/root'
                passive: true
                ssl: true
                timeout: 30

This is problematic line \League\FlysystemBundle\Adapter\Builder\FtpAdapterDefinitionBuilder::configureOptions:47
$resolver->setAllowedTypes('port', 'int');

directory_visibility cant set

hello

config file cant set "directory_visibility"
but main package available

app/vendor/league/flysystem/src/Config.php

A name for each instance ?

Hello,

If I want to make a storage registry to be able to get one dynamically, I see no way to do it. The tag flysystem.storage allow me to get an iterable, but I don't know which storages they are.

Is there a way to achieve that ? I could do it if each instance had a name (like the name of the service).

Last option I see is to make all storages public and inject the container to my registry, which is crappy.

syntax error, unexpected '$attributes' (T_VARIABLE)

Hello so im using the bundel in Symfony 5.4

and i got this error 👍

syntax error, unexpected '$attributes' (T_VARIABLE)

and this is my class 👍

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

use League\Flysystem\FilesystemOperator;
use League\Flysystem\StorageAttributes;
use League\Flysystem\FileAttributes;
use League\Flysystem\DirectoryAttributes;

class test_flysystemController extends AbstractController
{
    private $storage;

    public function __construct(FilesystemOperator $TESTStorage)
    {
        $this->storage = $TESTStorage;
    }

    /**
     * @Route("/demo_fs01", name="demo_fs01")
     */
    public function demo_fs01(): Response
    {



        $sortedListing = $this->storage->listContents('demo')
            ->sortByPath()
            ->toArray();

        foreach ($sortedListing as $key => $value) {

            dump($value["type"] . " - " . $value["path"]);
        }

        $allFiles = $this->storage->listContents('sante')
            ->filter(
                fn (StorageAttributes $attributes) => $attributes->isFile()
            );

        foreach ($allFiles as $key => $value) {

            dump($value["type"] . " - " . $value["path"]);
        }


        return $this->render('home/index.html.twig', [
            'controller_name' => 'HomeController',
        ]);
    }
}

what is wrong please

google storage type error?

hello

need help

symfony 4.4 upload image in google storage

    public function uploadFileWithStorage(\Symfony\Component\HttpFoundation\File\File $file, $uploadPath) {
        $stream = fopen($file->getRealPath(), 'r+');
        $ret = $this->storage->writeStream($uploadPath, $stream);
        fclose($stream);
        return $ret;
    }

and i see wrong type why? (application/octet-stream) why not img/png and etc?
image

UPDATE: sorry iam bad

bad because I looked wrong file function my problem is: upload filename.ext__uniqid() and copy i will fix it remove __uniqid() and working

Switch storage by environment

We have a setup where in a testing environment we use local storage, but in stage and prod we're on Azure. (Yes I know this is not ideal, but it's what I've been handed) Is there a way to make the defaultStorage option switch based upon the environment we're working in? Thanks.

[Question] Define/change container (rackspace or other cloud provider) at runtime ?

Hi there,

i'm looking for a way to define or change the container (rackspace or any other cloud provider) at runtime. The idea is that the container should come from a database.

It seems pretty easy outside of the Symfony service autowiring context but i'd like to make this work in symfony to keep dependencies working (VichUploaderBundle).

Any hints on how to achieve this ?
Thanks

Azure Too Few Arguements

When I try to use Azure as my storage environment I get this error:

Too few arguments to function MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::__construct(), 1 passed in /app/var/cache/dev/ContainerHJExcnV/getDefault_StorageService.php on line 9 and at least 3 expected

I'm not sure what I'm doing wrong. Could someone direct me on how to get this connection to work correctly? Thanks

This is my config:

services:
  MicrosoftAzure\Storage\Blob\BlobRestProxy:
    arguments:
      - connectionString: '%env(AZURE_CONNECTION_STRING)%'

flysystem:
  storages:
     default.storage:
      adapter: 'azure'
      options:
        client: 'MicrosoftAzure\Storage\Blob\BlobRestProxy'
        container: 'container_name'

Symfony no longer parses octal numbers starting with 0 alone

Starting with Symfony 5.1 following deprecation is triggered:

php bin/console lint:yaml config --parse-tags
  ERROR  in config/packages/flysystem.yaml
  Since symfony/yaml 5.1: Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0 at line 32 (near "directoryPerm: 0770").

The content of config/packages/flysystem.yaml:

flysystem:
  storages:
    sftp.storage:
      adapter: 'sftp'
      options:
        host: '<host>'
        port: 22
        username: '<user>'
        password: '<password>'
        privateKey: '<privateKey>'
        root: '<root>'
        timeout: 3
        directoryPerm: 0770

If I change 0770 to string representation '0770' I'm getting wrong directory permissions for newly generated folders on my sftp server. I think the issue is in SftpAdapterDefinitionBuilder.php, this should allow string values. If understand the code correctly the used library phpseclib/phpseclib expects directory permissions to be of type integer.

I'm working with Symfony 5.3 and flysystem-bundle 1.5.0

Flyssytem 2.2 - How to get name files ?

Hello, so now i can found the liste of my files in directory, but how to get the name files please ?

  $path = "";
        try {
            $listing = $this->storage->listContents("sante", FALSE);

            /** @var \League\Flysystem\StorageAttributes $item */
            foreach ($listing as $item) {
                $path = $item->path();

                if ($item instanceof \League\Flysystem\FileAttributes) {
                    // handle the file
                    dump($item["type"] . " - " . $item["path"]);

                    try {
                        $this->storage->copy($item["path"], "sante/test/files.pdf");
                    } catch (FilesystemException | UnableToCopyFile $exception) {
                        // handle the error
                    }
                } elseif ($item instanceof \League\Flysystem\DirectoryAttributes) {
                    // handle the directory
                    dump($item["type"] . " - " . $item["path"]);
                }
            }
        } catch (FilesystemException $exception) {
            // handle the error
        }

so i got the nameFiles with path, i want juste the name of the files, do u have a function please ?

$item["name"] ???

thanks

Update docs to reflect Flysystem 3

Can you update the docs to reflect that this bundle also works with Flysystem 3 (only BC break was custom adapters).

I've also requested that the flysystem repo reflect that versions 2 and 3 are not in beta anymore.

thephpleague/flysystem#1419

This will help people who are just getting started. Thanks.

Wrong default for visibility in yaml configuration

Bug Report

Q A
BC Break no (maybe)
Version 1.5.0

Summary

I encountered this when using league/flysystem (1.0.46) with the available league/flysystem-bundle (1.5.0).

In my opinion the default for visibility should not be null, but public instead. Alternatively the configuration node should be marked as required.

                            ->scalarNode('visibility')->defaultNull()->end() // <- This does not seem correct.
                            ->booleanNode('case_sensitive')->defaultTrue()->end()
                            ->booleanNode('disable_asserts')->defaultFalse()->end()

This is related to this issue

How to reproduce

Using the following yaml configuration:

flysystem:
  storages:
    example.storage:
      adapter: 'local'
      options:
        directory: '%kernel.project_dir%/var/storage/example/storage'

Somewhere in my code I'm calling createDirectory(). Make sure the directory does not yet exist.

That's caused by the way the default is retrieved. Currently array_key_exists() is used to check if the configuration object passed to the adapter method contains such a key. It is empty by default, so the fallback config is asked about that key (visibility). The fallback config contains null as value. That issue is already described in the linked issue at league/flysystem.

Error executing "CopyObject" digitaloceanspaces maybe need separate adapter

Some problem when try to execute rename function with digitaloceanspaces

            "name": "league/flysystem-aws-s3-v3",
            "version": "dev-master",

"league/flysystem-bundle": "dev-master"

flysystem:
  storages:
    reaources.storage:
      adapter: 'aws'
      options:
        client: 'Aws\S3\S3Client' # The service ID of the Aws\S3\S3Client instance
        bucket: 'minimoj-consumer'
        prefix: 'minimoj'

services:
  Aws\S3\S3Client:
    arguments:
      - endpoint: 'https://minimoj-consumer.ams3.digitaloceanspaces.com'
        version: 'latest'
        region: 'ams3'
        use_path_style_endpoint: true
        credentials:
          key: '%env(S3_STORAGE_KEY)%'
          secret: '%env(S3_STORAGE_SECRET)%'

I attemted chnage ACL to public but still had this error
return true when I called has function for original file, what problem is here, maybe need reduce verstion ?

Error executing "CopyObject" on "https://minimoj-consumer.ams3.digitaloceanspaces.com/minimoj-consumer/minimoj/download_files/adrecord/baby_bjorn/20200909115234_hello_anmol.csv"; AWS HTTP error: Client error: `PUT https://minimoj-consumer.ams3.digitaloceanspaces.com/minimoj-consumer/minimoj/download_files/adrecord/baby_bjorn/20200909115234_hello_anmol.csv` resulted in a `404 Not Found` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><BucketName>minimoj-consumer</BucketName><RequestId>t (truncated...)
 NoSuchKey (client):  - <?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><BucketName>minimoj-consumer</BucketName><RequestId>tx000000000000083419401-005f58c420-aaf305-ams3b</RequestId><HostId>aaf305-ams3b-ams3-zg02</HostId></Error>
    /**
     * Rename a file.
     *
     * @param string $path    Path to the existing file.
     * @param string $newpath The new path of the file.
     *
     * @throws FileExistsException   Thrown if $newpath exists.
     * @throws FileNotFoundException Thrown if $path does not exist.
     *
     * @return bool True on success, false on failure.
     */
    public function rename($path, $newpath);
$path = 'download_files/adrecord/baby_bjorn/20200909115234.csv', $nwPAth = 'download_files/adrecord/baby_bjorn/20200909115234_hello_anmol.csv'
$this->getStorage()->rename($path, $nwPAth);

I faced with this problem when try to used flysystem-concatenate plugin, but after debug I undertsand problem with CopyObject

Symfony 6 compatibility

Now that we have Symfony 6 officially released, I hope the bundle can be adjusted to support it.

Service ids should be prefixed

Currently, the storage gets stored as a service id equal to the storage name you provide. This is very likely to create conflicts with ids of other bundles.
The id should instead be prefixed with flysystem.storage. instead, to avoid conflicts in the container.

Alternative to storing ftp/sftp password in config

I'm still relatively new to the Symfony game, so maybe I'm missing something and just don't know where to look. Currently, I'm creating a project which needs to have the ability to reach out to multiple client's ftp/sftp servers. Configuring the 20 different servers doesn't seem like it will be all that difficult (thanks to this bundle!).

My issue is that I would like to avoid putting the plain text password into a .yaml file that would be committed to my repository. Is there a built-in option already which would allow me to store the sensitive configurations elsewhere? My current idea would be to use doctrine and mysql for storage/retrieval, but I'm not sure how to go about injecting the storage services into the configuration.

I don't mind doing my own research, but I'm not even really sure where to begin...

[Question] How can I get the full path to the file?

Hi.

I'm using Flysystem-bundle with local adapter.
My configuration is:

flysystem:
    storages:
        default.storage:
            adapter: 'local'
            options:
                directory: '%kernel.project_dir%/public/samples/'

Also, I have created table, where I have file name with extension (e.g. "1.pdf").
I need to pass full path to the frontend but get() method, located in the FilesystemInterface is deprecated.

How can I do this?
Thanks.

How to access files in front

Hello,

I'm using Flysystem-bundle with local and s3 (scaleway) adapter.

I can't seem to find any examples or documentation that demonstrates how to access files (view / download) in the front, with twig for my case.

Am I doing it wrong or is it a use that is not intended with the fly system ?

Error Google Cloud Storage

Hello, I have configured flysystem-bundle in Symfony 5, also in Google Storage, but I have the following error:
{ "error": { "code": 401, "message": "Invalid Credentials", "errors": [ { "message": "Invalid Credentials", "domain": "global", "reason": "authError", "locationType": "header", "location": "Authorization" } ] } } \vendor\google\cloud-core\src\RequestWrapper.php (line 362)

`flysystem:
storages:
default.storage:
adapter: 'local'
options:
directory: '%kernel.project_dir%/var/storage/default'

    gcs.storage:
        adapter: 'gcloud'
        options:
            client: 'gcloud_client_service' # The service ID of the Google\Cloud\Storage\StorageClient instance
            bucket: 'test-storage'
            #prefix: 'optional/path/prefix'
            api_url: 'https://storage.googleapis.com'`

gcloud_client_service: class: Google\Cloud\Storage\StorageClient arguments: - projectId: 'academico-214422' - keyFilePath: '../credentials333.json'

Help me

Register a stream wrapper for each registered filesystem

For example

flysystem:
    storages:
        default.storage:
            adapter: 'local'
            options:
                directory: '%kernel.project_dir%/var/storage/default'

flysystem+default.storage://foo/bar/bat.csv points to %kernel.project_dir%/var/storage/default/foo/bar/bar/csv.

Similar to https://github.com/twistor/flysystem-stream-wrapper, but up to date.

This wrapper works with recent Flysystem: https://github.com/m2mtech/flysystem-stream-wrapper

Thinking about it further, it seems like a thing which could be opted-in per filesystem, something like

flysystem:
    storages:
        some.storage:
            adapter: 'asyncaws'
            stream_wrapper: true

Could not load package ezsystems/ezplatform

I use symfony/framework-bundle v5.0.5 in docker-compose. And when I try executed composer require league/flysystem-bundle I faced wth that:

  [RuntimeException]                                                           
  Could not load package ezsystems/ezplatform in http://repo.packagist.org: [  
  UnexpectedValueException] Could not parse version constraint dev-load-varni  
  sh-only-when-used as ^2.0@dev: Invalid version string "^2.0@dev"             
  [UnexpectedValueException]                                                   
  Could not parse version constraint dev-load-varnish-only-when-used as ^2.0@  
  dev: Invalid version string "^2.0@dev"  

what I'm doing wrong or what need to do ?

Controller to access assets

Would it be in the scope of this bundle to have a controller you could access like /file/{path} which would then expose the file with the given path? If so I would love to create a PR

Drop support for dependencies in EOL

I think this bundle should require PHP 7.4 or PHP 8.x, Symfony 4.4, 5.4 or 6.x.

I can make this change and run tests and submit a PR if you agree.

[FTP Adapter] Using SSL, we get an error : ftp_fput(): SSL_shutdown failed

Hi,

I am using Flysystem with the FTP adapter and my configuration is

flysystem:
    storages:
        default.storage:
            adapter: 'ftp'
            options:
                host: ftpupload.net
                username: <username>
                password: <password>
                port: 21
                ssl: true          #seems to bug...
                passive: true
                #ignore_passive_address: true
                root: /myDirectory

However, when I upload a file, I got an error :

ftp_fput(): SSL_shutdown failed

What is wrong ?

Thanks,

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.