Code Monkey home page Code Monkey logo

Comments (3)

micschk avatar micschk commented on July 20, 2024

OK, I couldn't find anything in the code setting the existing uploads so I've added it. If you like I can send a PR for this addition.

screen shot 2018-07-13 at 11 46 25

/**
     * Set initial values to FilePondField
     * See: https://pqina.nl/filepond/docs/patterns/api/filepond-object/#setting-initial-files
     * @TODO: (especially in front-end) existing file-IDs may be spoofed which may result in unauthorized attachment of files
     * 
     * @return array
     */
    public function getExistingUploadsData()
    {
        // Both Value() & dataValue() seem to return an array eg: ['Files' => [258, 259, 257]]
        $fileIDarray = $this->Value() ?: ['Files' => []];
        if(!isset($fileIDarray['Files']) || !count($fileIDarray['Files'])) return [];

        $existingUploads = [];
        foreach($fileIDarray['Files'] as $fileID) {
            if($file = File::get()->byID($fileID)){
                $existingUploads[] = [
                    // the server file reference
                    'source' => (int) $fileID,
                    // set type to local to indicate an already uploaded file
                    'options' => [
                        'type' => 'local',
                        // file information
                        'file' => [
                            'name' => $file->Name,
                            'size' => (int) $file->getAbsoluteSize(),
                            'type' => $file->getMimeType(),
                        ]
                    ]
                ];
            }
        }

        return $existingUploads;
    }

    public function Field($properties = array())
    {
        ...
        $config = [
            ...
            'files' => $this->getExistingUploadsData(),
        ];
        ...
    }

from silverstripe-base.

lekoala avatar lekoala commented on July 20, 2024

Yes sure I'd be happy to merge a PR doing that :-)

I haven't done it so far because I'm using only Filepond in scenarios where I don't need displaying existing files, but it's most certainly something I'll need someday!

from silverstripe-base.

lekoala avatar lekoala commented on July 20, 2024

merged into master

from silverstripe-base.

Related Issues (4)

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.