vue-dropzone icon indicating copy to clipboard operation
vue-dropzone copied to clipboard

Cannot display images correctly using manuallyAddFile()

Open NeoTianHow opened this issue 6 years ago • 8 comments

I am trying to display images using the manuallyAddFile() method. However, I could not display the images for some reason. Here are my codes: Do Note that I am passing in a base64URL Is that the cause of this issue?

 dropOptions: {
        url: "https://httpbin.org/post",
        acceptedFiles: "image/*",
        // maxFiles: 1,
        addRemoveLinks: true,
        autoProcessQueue: false,
        thumbnailWidth: 160,
        thumbnailHeight: 160
      }

setTimeout(() => {
          this.form.varient.files.forEach(eachFile => {
            var file = {
              size: eachFile.size,
              name: eachFile.name,
              type: eachFile.type
            };
            this.$refs.myVueDropzone.manuallyAddFile(file, eachFile.dataURL);
          });
        }, 0);

image

NeoTianHow avatar Jul 03 '19 12:07 NeoTianHow

@rowanwins

NeoTianHow avatar Jul 03 '19 12:07 NeoTianHow

@ndarilek @ejucovy @andrewharvey @keevitaja

NeoTianHow avatar Jul 03 '19 12:07 NeoTianHow

Hi @NeoTianHow

Yes I suspect the base64url is the cause of the issue. If you look at these lines you will see that we attempt some basic validation before creating a thumbnail.

Also please don't tag people on issues unnecessarily - it is not their job (particularly if they aren't maintainers) to provide you with support within 15 minutes of the issue being posted.

rowanwins avatar Jul 03 '19 12:07 rowanwins

Hi, @rowanwins Thanks for the reply! I am sorry for tagging you, my apologies. If base64URL does not work, is there a way to display the image using a file object? Just to give you more context, whenever a user decides to upload a photo in the dropzone, I used the @vdropzone-file-added event listener to receive the user-upload file. I will then add the file into a list. Right now, I want to display the images whenever the user revisits the dropzone. I have the file object, how can I display it?

NeoTianHow avatar Jul 03 '19 12:07 NeoTianHow

I have the same issues, Does my url wrongly submitted?

 let mockFile: any = {

      name: ${imageObject.id}_${

        imageObject.source

          .split('/')

          .pop()

          .split('#')[0]

          .split('?')[0]

      },

      id: imageObject.id,

      accepted: true,

      kind: 'image',

      status: 'fetched',

      type: 'image/jpeg',

      upload: {

        filename: imageObject.source

          .split('/')

          .pop()

          .split('#')[0]

          .split('?')[0]

      }

    }

    ;(this.$refs as any).images.manuallyAddFile(

      mockFile,

      imageObject.source // https://some.site/images/products/831621/5tKVv5j3LTXcogJhuMW8esO7nvktXMwoIvOYLvqM.png,

     () => {

        console.log('Callback')

      },

      null,

      {

        dontSubstractMaxFiles: true,

        addToFiles: true

      }

    )

  })

`

vano20 avatar Aug 13 '19 07:08 vano20

@NeoTianHow hey sorry for the tag as this issue likely not progressing.. Did you by any chance already solving this issue?

vano20 avatar Aug 19 '19 03:08 vano20

In addition to extensions ("fileUrl.indexOf(".jpg")") user might need to supply files without extensions (eg. server side is rendering the image with permission checks) or as base64.

For me, I am using manuallyAddFile with type: "image/jpeg" and without file extension. Could the script just check if the defined type matches image/* or kind: 'image' or something like that - when there is no extension?

For now, I did solve it via manuallyAddFile(Object, /dynamic/filepath#.jpg) - with #.jpg it assumes it to be an image and server loads it as supposed.

nviitala avatar Dec 04 '19 06:12 nviitala

Being worked on in #549

rowanwins avatar May 09 '20 04:05 rowanwins