pqina / filepond-plugin-image-preview

🖼 Show a preview for images dropped on FilePond
https://pqina.nl/filepond
MIT License
46 stars 26 forks source link

Allow image preview when using local? #26

Closed lukepass closed 4 years ago

lukepass commented 4 years ago

Hello, how can I add a file preview when using FilePondPluginFileEncode? I don't have server side methods and so when I am loading the initial files they cannot be loaded using the load method. Can I provide the previewUrl manually?

Thanks!

rikschennink commented 4 years ago

Encoding is only for sending files to the server. To preview local files you can do this:

FilePond.create({
  server: {
    load: (src, load) => {
      fetch(fileSrc).then(res => res.blob()).then(load);
    }
  }
})
lukepass commented 4 years ago

Thanks @rikschennink, this is almost working for me. I have the following starting files property:

[
    {options: {type: "local"}, source: 672}, // this is for FilePond.create
    {options: {type: "local"}, source: 673} // this is for FilePond.create
]

But since I don't implement the fetch method (I don't use server property at all thanks to FilePondPluginFileEncode) I need a method to get the URL to preview. I tried something like this:

[
    {options: {type: "local"}, source: {id: 672, url: 'mypreview.jpg'}}, // this is for FilePond.create
    {options: {type: "local"}, source: {id: 673, url: 'mypreview2.jpg'}}, // this is for FilePond.create
]

And then:

  load: function(source, load) {
    fetch(source.url).then((res) => res.blob()).then(load);
  },

But this is not working and giving me an error about "split". Maybe the source property can only be a string and not a complex object?

Thanks!

rikschennink commented 4 years ago

You could use the file-poster plugin? https://pqina.nl/filepond/docs/patterns/plugins/file-poster/

lukepass commented 4 years ago

Exactly what I was looking for, really thank you!

rikschennink commented 4 years ago

@lukepass fantastic, I'll close the issue then 👍

lukepass commented 4 years ago

@rikschennink sorry one last question, when using FilePoster the image is always very big. The previewer plugin instead is able to detect dimensions. How can I specify them with poster plugin?

I tried adding width and height (not documented, I just tried) but it didn't work.

Thanks!

EDIT: it seems related to these:

rikschennink commented 4 years ago

The post will always take up the entire item, at the moment that's the way it's designed.

patrickvlt commented 4 years ago

The post will always take up the entire item, at the moment that's the way it's designed.

That's unfortunate and unhelpful. How can we achieve the same functionality with ImagePreview?

nehadhiman6 commented 1 year ago

Update: There are new props added.

filePosterHeight filePosterMinHeight filePosterMaxHeight

see here thanks @fratzinger