question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addFile function not triggering image preview plugin to draw preview

See original GitHub issue

I create an image file from a blob and use the addFile function

const imageFile = new File([filecontent], filename, { type: contentType });
this.filePond.addFile(imageFile);

the file gets added but the preview doesn’t render and debugging shows the image plugin code doesn’t get invoked

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

3reactions
kevduggancommented, Jun 19, 2018

I was doing something very convoluted

createImageFromBlob(filename: string, blob: Blob) {
  const reader = new FileReader();
  reader.addEventListener('load', () => {
    let contentType: string = blob.type;
    const imageFile = new File([reader.result], filename, { type: contentType });
    this.filePond.addFile(imageFile);
  }, false);
  if (blob) {
    reader.readAsDataURL(blob);
  }
}

some of the plugins (the image size validation one for example) use URL.createObjectURL to generate the image object to get the height and width. with the above FileReader based method of creating the initial file, that image never actually loaded.

the following works fine (that image loads and height and width are calculated)

this.filePond.addFile(new File([blob], filename, { type: blob.type }));

note the type needs to be set on the file to pass the File type validation plugin

0reactions
dzvidcommented, Aug 23, 2022

thank you @kevduggan !!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are my Filepond uploads not working on Android devices ...
The issue turned out to be the image attachments on my Android device. Set up some checks for checking the file types and...
Read more >
Using files from web applications - Web APIs - MDN Web Docs
Let's say you're developing the next great photo-sharing website and want to use HTML to display thumbnail previews of images before the user ......
Read more >
Why is Preview not Working on Your Mac and How to Fix It?
Sometimes it happens that the Preview app does not work. For example, it won't open an image or load thumbnails.
Read more >
Using the FileReader API to preview images in React
Images make up a significant proportion of data transmitted on the internet. More often than not, clients have to upload image files from...
Read more >
Web IDE - GitLab Docs
On self-managed GitLab, by default this feature is not available. To make it available ... There are two ways to preview Markdown content...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found