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

Preloaded image Placeholder #105

Open
joaotomasrobalo opened this issue Aug 17, 2019 · 11 comments
Open

Preloaded image Placeholder #105

joaotomasrobalo opened this issue Aug 17, 2019 · 11 comments

Comments

@joaotomasrobalo
Copy link

Hello.

I have a node.js + Express server, and the only images that I have stored are the user profile pictures. Those images are stored on an Amazon S3 bucket. How can I open the user profile with the image loaded in the filepond widget?

Screenshot 2019-08-17 at 23 40 33

I want to open the page with the FilePond input loaded in that state (with the user profile picture already loaded)

I have tried to set initial files but what is happening is that filepond loads a blank image and not the image I'm trying to get from Amazon S3

Thanks in advance!

@rikschennink
Copy link
Collaborator

Sounds like you have to implement the FilePond server.load end point

@joaotomasrobalo
Copy link
Author

Sounds like you have to implement the FilePond server.load end point

Do I have to implement an endpoint in my server? I have the URL of the user profile picture (stored in an Amazon S3 bucket)

Can you give me an example on how to do it? I'm using jquery...
Thank you

@rikschennink
Copy link
Collaborator

I think something like this should work.

// where id is your S3 file URL
FilePond.create({
    server: {
        load: (id, load) => {
            fetch(id).then(res => res.blob()).then(load)
        }
    }
})

Please make sure the CORS headers for the files on S3 are configured properly

https://pqina.nl/filepond/docs/patterns/api/server/#load-1

@bt1
Copy link

bt1 commented Aug 21, 2019

Also make sure the access controls on the object are set correctly in s3. Literally spent a few hours on this yesterday.

@joaotomasrobalo
Copy link
Author

I think something like this should work.

// where id is your S3 file URL
FilePond.create({
    server: {
        load: (id, load) => {
            fetch(id).then(res => res.blob()).then(load)
        }
    }
})

Please make sure the CORS headers for the files on S3 are configured properly

https://pqina.nl/filepond/docs/patterns/api/server/#load-1

The method is not being called... It doesn't fetch anything. Outside FilePond.create() it does fetch the image. However the code inside server.load is not being called

@rikschennink
Copy link
Collaborator

rikschennink commented Aug 27, 2019

then your file probably does not have type local
https://pqina.nl/filepond/docs/api/instance/properties/#files

edit: updated link

@joaotomasrobalo
Copy link
Author

File does not have type local? What does that mean?

I worked around it and added the file with _pond.addFile(file) right after the creation... It's a work around but it works...

@rikschennink
Copy link
Collaborator

It’s right in the docs that I linked to

@ViniciusGularte
Copy link

Same problem here, you managed to discover a solution @joaotomasrobalo ?

@joaotomasrobalo
Copy link
Author

joaotomasrobalo commented Nov 9, 2019

@ViniciusGularte I did. It's a workaround and not a perfect solution.

After the creation of the filepond object you fetch the img and add it to the object.
Like this:

   fetch(url).then(res => res.blob()).then(blob => {
            var file = new Blob([blob], {
                type: 'image/png'
            });
            fromLoad = true;
            _pond.addFile(file);
   })

If you can't make it work with this let me know...

@predam
Copy link

predam commented Dec 5, 2022

The "load" option from the server part is not working, or perhaps its scope is not documented enough.
Here is a workaround working for me to achieve the image preview.

const [state, setState] = useState([initialImageUrl]);
const [canUpload, setCanUpload] = useState(false);

const getServerConfig = () => {
  if(!canUpload) { return undefined}
  
  return {
  /// your code for server
  process: () => {}, // I usually use just the upload part.
  revert: () => setState(undefined), // use this if you want to have the revert button without triggering the DELETE request
  }
}

....

<FilePond 
  files={state}
  server={getServerConfig()}
  onaddfile={() => setCanUpload(true)}
  onupdatefiles={(data) => setState(data)}
/>

This implementation shows the initial image without triggering the upload.

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

5 participants