Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Enable Video Upload #216

Open
indigofa opened this issue Apr 13, 2020 · 6 comments
Open

Enable Video Upload #216

indigofa opened this issue Apr 13, 2020 · 6 comments

Comments

@indigofa
Copy link

This library is awesome, thank you for making it.
I'm using image upload like in the code bellow and it's working fine, I would like to know is there a way I can do the same and enable Video Upload aswell

widgets = {
    [
        ImageBlockConfig({
            options: {
                upload_handler: handleUploadContentMediaHander,
            },
        }),
    ]
}
  const handleUploadContentMediaHander = (file, imageBlock) => {
    setLoadingContentMedia(true)
    imageBlock.startLoader()

    const ext = file.name.substr(file.name.lastIndexOf(".") + 1)
    const filename = `${uuidv4()}.${ext}`

    const getSignedUrl = async cb => {
      const response = await Api.getImageUploadUrl(getToken(), [
        { key: filename },
      ])

      cb(null, response)
    }

    const uploadMedia = async (storage, cb) => {
      try {
        await fetch(storage[0].url, {
          method: "PUT",
          body: file,
        })

        setLoadingContentMedia(false)
        imageBlock.stopLoader()
        cb(null, storage)
      } catch (err) {
        setLoadingContentMedia(false)
        imageBlock.stopLoader()
        cb(err)
      }
    }

    const transformMediaContent = async (storage, cb) => {
      const type = file.type.split("/")[0]
      try {
        const result = await Api.transformMedia(
          getToken(),
          type,
          storage[0].key
        )

        cb(null, result)
      } catch (err) {
        cb(err)
      }
    }
@indigofa indigofa changed the title Adding video Upload Adding Video Upload Apr 13, 2020
@indigofa indigofa changed the title Adding Video Upload Enable Video Upload Apr 13, 2020
@michelson
Copy link
Owner

Hi , you could take the image block as an starting point. In this case I would add a new block type to support video and make a different implementation. If you can make an fork and share your implementation I could help a bit more

@indigofa
Copy link
Author

Hi Michelson,

I will try to implement tonight and get back

Thank you

@garmjs
Copy link

garmjs commented Apr 14, 2020

Maybe can make the same component accept images/*,videos/* @michelson

@garmjs
Copy link

garmjs commented Apr 14, 2020

@indigofa are you working on it!

@indigofa
Copy link
Author

@michelson I get this file as starting point image.js I want to create video uploader, my question is how can I allow to select video files ex mp4, right now I'm allowed to select only images extensions

thanks

@indigofa
Copy link
Author

indigofa commented Apr 19, 2020

@michelson can you please give me idea how can I solve this issue I'm having this is the video upload codesandbox I get image.js as a starting point, the problem I'm having is when I try to select the file I'm unable to select video files with extensions .mp4 or any other video extensions, it is allowed only image file.

Screen Shot 2020-04-20 at 12 39 38 AM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants