filepond-plugin-image-transform icon indicating copy to clipboard operation
filepond-plugin-image-transform copied to clipboard

[Feature request] Add method on file to retrieve the blob of the transformed image

Open Tofandel opened this issue 4 years ago • 6 comments

It would be nice to be able to access the transformed blob from the file using something like

const blob = await file.getTransformedImage();

Basically like what filepond-plugin-encode does with file.getFileEncodeDataURL() but without the encoding part

Tofandel avatar Jun 20 '21 15:06 Tofandel

Hi, you can use onpreparefile to access the data. Would that work for your use case?

rikschennink avatar Jun 21 '21 06:06 rikschennink

Yes that's what I'm currently using, but in a weird way. I extend the Filepond file with a promise and then get the result of the promise or await in the submission, but it would definitely be simpler if this was built in with a method directly on the Filepond file

    extendFile(file) {
      if (file && !file.output) {
        const pr = new Promise((resolve, reject) => {
          const t = setTimeout(() => reject(new Error('Timeout')), 30000);
          file.extend('resolve', (...args) => {
            clearTimeout(t);
            resolve(...args);
          });
        });
        pr.catch(() => {});
        file.extend('output', pr);
      }
      return file;
    },
    updateFiles() {
        this.$emit('input', this.extendFile(this.$refs.pond.getFile()));
    },
    prepare(file, output) {
      file.resolve(output);
    },

Then on submit in a different component

const blob = await file.output;

Tofandel avatar Jun 21 '21 17:06 Tofandel

Yeah that is a bit odd, I'll see if I can add this.

rikschennink avatar Jun 23 '21 07:06 rikschennink

I've added requestPrepare to the fileItem API, it returns a Promise which resolves with the prepared file item.

rikschennink avatar Jul 08 '21 10:07 rikschennink

requestPrepare works well on the first call, but on subsequent calls the promise never resolves, that's a problem when resubmitting a form

await file.requestPrepare(); // This one resolves a Blob
await file.requestPrepare(); // Never resolves so loops indefinitely

The result needs to be cached

Tofandel avatar Mar 07 '22 17:03 Tofandel

@Tofandel I'll look into this when I have some time.

rikschennink avatar May 09 '22 05:05 rikschennink