tinymce icon indicating copy to clipboard operation
tinymce copied to clipboard

images_upload_handler 自定义上传图片失败

Open wwq146213 opened this issue 3 years ago • 2 comments

image 上传之后获取不到图片信息

wwq146213 avatar Jun 28 '22 07:06 wwq146213

z有人吗

wwq146213 avatar Jun 28 '22 09:06 wwq146213

image 上传之后获取不到图片信息

用images_upload_handler函数

dengshicheng1996 avatar Jul 04 '22 10:07 dengshicheng1996

I have the same issue. I see the demo code here, and not work.

If I no call _progress function, not happened.

If I call _progress(100); I get error message

images_upload_handler: (blobInfo, _progress) => new Promise(success => {
    setTimeout(() => {
      success('https://www.google.com/logos/google.jpg');
      _progress(100);
    }, 1000);
}),
Error: Errors: 
Failed path: (data > src > value)
Expected type: string but got: number

Input object: {
  "src": {
    "value": 100,
    "meta": {}
  },
  "alt": "",
  "dimensions": {
    "width": "",
    "height": ""
  },
  "fileinput": [
    {}
  ]
}

But. If add _progress function the link, resolve this issue.

images_upload_handler: (blobInfo, _progress) => new Promise(success => {
  setTimeout(() => {
    _progress('https://www.google.com/logos/google.jpg')
    success()
  }, 1000);
}),

image

My solution is that I upgraded to v6. Unfortunately I was v5.

icetee avatar Oct 28 '22 21:10 icetee

This code can work normally.

 images_upload_handler: function(blobInfo) {
          const formData = new FormData()
          formData.append('image', blobInfo.blob(), blobInfo.filename())

          return fetch('http://mysite.com/api/upload', {
            method: 'POST',
            body: formData,
            headers: { Authorization: 'Bearer ' + window.sessionStorage.getItem('token') }
          })
            .then(response => {
              if (!response.ok) {
                throw new Error('Network response was not ok')
              }
              return response.json()
            })
            .then(data => {
              if (data && data.data && data.data.location) {
                return data.data.location
              } else {
                throw new Error('Unable to upload image')
              }
            })
            .catch(error => {
              console.error(error)
              throw new Error('Image upload failed: ' + error.message)
            })
        }

toyRan avatar Jun 29 '23 08:06 toyRan

Yes this code

This code can work normally.

 images_upload_handler: function(blobInfo) {
          const formData = new FormData()
          formData.append('image', blobInfo.blob(), blobInfo.filename())

          return fetch('http://mysite.com/api/upload', {
            method: 'POST',
            body: formData,
            headers: { Authorization: 'Bearer ' + window.sessionStorage.getItem('token') }
          })
            .then(response => {
              if (!response.ok) {
                throw new Error('Network response was not ok')
              }
              return response.json()
            })
            .then(data => {
              if (data && data.data && data.data.location) {
                return data.data.location
              } else {
                throw new Error('Unable to upload image')
              }
            })
            .catch(error => {
              console.error(error)
              throw new Error('Image upload failed: ' + error.message)
            })
        }

thank you is working.

mariojgt avatar Jul 22 '23 11:07 mariojgt

Correct, TinyMCE 6 changed the images_upload_handler config to use promises, rather than success and failure callbacks.

https://www.tiny.cloud/docs/tinymce/6/upload-images/#images_upload_handler

TheSpyder avatar Aug 18 '23 01:08 TheSpyder