Filepond: [React] Can't load File preview from URL

Created on 21 Apr 2018  Â·  22Comments  Â·  Source: pqina/filepond

First of all thanks for this component, it's great!

On the React version, when uploading a picture, I get the preview and everything works great, then I store in my resource the picture url. But then when I consult my resource, I try to set up the initial state with a file, but somehow I can't get the preview of that image url.

My code :

<FilePond allowMultiple={false} server={{process: this.handleProcessing.bind(this)}}>
    <File source='http://liviogama.com/img/Pioneer-CDJ2000-Nexus.png' type='local'/>
</FilePond>

Result :
capture d ecran 2018-04-21 a 02 07 51

All 22 comments

Hey! That’s a bit odd, I’m currently on a short trip, will look into this when I get back later this week.

@LivioGama If you remove the type="local" from the File component it should work. FilePond will now load the file by URL.

The type="local" is only for files that are inaccessible from the web. When type is set to local the file is requested via the server load end point ( which by default returns a webpage in a react app, which is also why the file is so tiny ).

If you inspect the network tab of your developer tools you'll see the request load?=filename.png.

screen shot 2018-04-26 at 14 11 57

There is no picture preview in the solution you gave me. I would expect the remote image to have the same look than the ‘just uploaded successfully’ picture

Have you removed the type="local"?

Removing the type=local will cause the file to upload, then the model will change and the page will re-render, then the file upload again, in an infinite loop. I will try to disable auto upload to see what it does, I'm coming back to you.

Have you tried implementing the load API end point? It basically loads the file and returns it from the server, you can find and example here: https://github.com/pqina/filepond-boilerplate-php/blob/master/public/api/index.php#L45

I'm thinking of making this optional ( as when the file is accessible from the browser it's unnecessary ).

Hi!

It's explained on the server page in the docs.

So this would be the default:

<FilePond allowMultiple={true}
          maxFiles={3}
          server={{
              load: "load.php?id="
          }}>
</FilePond>

You could try using a custom function and getting the file with fetch. I haven't tested this but it should work.

<FilePond allowMultiple={true}
          maxFiles={3}
          server={{
              load: (uniqueFileId, load, error) => {
                  fetch(uniqueFileId)
                    .then(res => res.blob())
                    .then(load)
                    .catch(error)
              }
          }}>
</FilePond>

Thanks a lot for your patience !
Unfortunately it is not working, the load function is never called. Here is my ready to use example :

<FilePond allowMultiple={false}
    server={{
        load: (uniqueFileId, load, error) => {
            console.log('TEST')
            fetch(uniqueFileId)
                .then(res => res.blob())
                .then(load)
                .catch(error)
        }
    }}>
    <File source='http://liviogama.com/img/livio.png'/>
</FilePond>

No "TEST" is shown in the log. Note that if I add a process function, and drop a file, it will upload successfully !

Actually I tried :

<FilePond allowMultiple={false}
                    server={{
                      process: this.handleProcessing,
                      revert: this.handleRevert,
                      fetch: this.handleFetch,
                      restore: this.handleRestore,
                      load: this.handleLoad
                    }}>
            <File source='http://liviogama.com/img/livio.png'/>
</FilePond>

And only the process method is called :(

@LivioGama Sorry for the confusion, the type="local" needs to be present on the File for the load method to be called.

Even with type="local" no other method than process are called for me. I'm using the latest "react-filepond": "^2.0.4" version

@LivioGama Okay, I seem to have reproduced the problem here, working on a fix.

@LivioGama Just publish version 2.0.6 of the react adapter and version 1.4.0 of the core library. Please let me know if this fixes the issue.

@rikschennink - please your help on this.

  1. I am using something similar to below code as recommended above. Load method is called, however image is not loaded in preview mode. It only shows image name in a box with dark background .
  2. When I click in "Remove" for an initial file, I realized that server.revert method is not called, please would you tell why?
  3. Is there any way we can allow users to download initial files from filepond component?

<FilePond allowMultiple={true} maxFiles={3} server={{ revert: this.handleRevert, load: this.handleLoad }} > <File key={123} source={imageURL1} origin='local' /> <File key={456} source={imageURL2} origin='local' /> </FilePond>

Hi!

  1. Does your load method return the file data?

  2. Revert is only called for temporary files, you can set up a custom remove method in true onremovefile callback.

  3. There’s currently no default functionality for this, but maybe a click handler on the filepond root will give you the target element clicked and you can use that to get the matching file from FilePond and serve that file to the user as a download?

hi @rikschennink , pls your help with question #1 & #3

1.- Yes, it does.
2.- Got it.
3.- Just added onClick={this.handleClick} as property in FilePond, and defined the handler below but it is not called. Any suggestion please?

handleClick = e => {
console.log(e);
}

  1. No errors in dev console? If not, can you past the load function here?

  2. Great!

  3. Then I'm not sure, maybe you can use JavaScript addEventListener to catch events that bubble up the DOM tree.

Hi there, is there an example for the jquery adapter as well? I can't get the image fetched after dragdropping it form google image search for instance.

@mverstegen Please post questions to StackOverflow

Does anyone solve this issue?

Have you tried implementing the load API end point? It basically loads the file and returns it from the server, you can find and example here: https://github.com/pqina/filepond-boilerplate-php/blob/master/public/api/index.php#L45

I'm thinking of making this optional ( as when the file is accessible from the browser it's unnecessary ).

i also have this issue, but the given link is not even public.

@dashawk The link indeed doesn't work.

Should be: https://github.com/pqina/filepond-server-php/blob/master/index.php

Was this page helpful?
0 / 5 - 0 ratings