Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Image #23

Open
espositodaniele opened this issue Aug 10, 2022 · 4 comments
Open

Upload Image #23

espositodaniele opened this issue Aug 10, 2022 · 4 comments

Comments

@espositodaniele
Copy link

espositodaniele commented Aug 10, 2022

Hello,

how we can manager uploap image?
The docs from unlayer says that we need to add a callbacks like the this:

unlayer.registerCallback('image', function(file, done) {
  var data = new FormData()
  data.append('file', file.attachments[0])

  fetch('/uploads', {
    method: 'POST',
    headers: {
      'Accept': 'application/json'
    },
    body: data
  }).then(response => {
    // Make sure the response was valid
    if (response.status >= 200 && response.status < 300) {
      return response
    } else {
      var error = new Error(response.statusText)
      error.response = response
      throw error
    }
  }).then(response => {
    return response.json()
  }).then(data => {
    // Pass the URL back to Unlayer to mark this upload as completed
    done({ progress: 100, url: data.filelink })
  })
})

How can we add this feature?

Many thanks

@alies-dev
Copy link
Member

alies-dev commented Aug 10, 2022

That's currently not possible. PRs are very welcome to implement this

@alies-dev
Copy link
Member

Hey @espositodaniele

What exactly do you want to implement for images? I'm exploring options how to improve the package, your input is very welcome.

@espositodaniele
Copy link
Author

espositodaniele commented Nov 11, 2022

What I've done is to upload photo that are sorted on my server, and at the moment it is not configurable.

I needed to force the plug-in directly from .vue files.

Would be helpful to have an option to indicate our root folder where to place image and then provide that information to the api that store image.

Here is the code I've added to your UnlayerEditor.vue

window.unlayer.registerCallback('image', (file, done) => {
    let data = new FormData();
    data.append('file', file.attachments[0]);
    fetch('/api/upload-unlayer', {
        method: 'POST',
        headers: {
            'Accept': 'application/json',
            'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
        },
        body: data
    }).then(response => {
        // Make sure the response was valid
        if (response.status >= 200 && response.status < 300) {
            return response.json()
        }
        let error = new Error(response.statusText);
        error.response = response;
        throw error
    }).then(data => done({progress: 100, url: data.url}))
});

@alies-dev
Copy link
Member

guys, do you meth this upload functionality?
image

Also, I couldn't find any documentation for image callback/event, can you please provide some?

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

No branches or pull requests

2 participants