Uploading images with TinyMCE does not replace the src attribute inside the image tag
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, react
- Lĩnh vực
- frontend
Hướng nghiên cứu
Start with the TinyMCE <Editor> setup and the handleImageUpload and submit handlers shown in the issue; trace how uploadImages() results are used before the form is posted. The expected outcome is that the image src contains the uploaded location at submission time, but the issue does not identify repository files or tests to check.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
📝 Provide detailed reproduction steps (if any)
I'm trying to upload images from my React frontend to my Laravel backend using TinyMCE the image plugin that is provided from TinyMCE. My backend and frontend are glued together with inertiajs.
The upload process works fine and saves the image, but when I try to save the form with the image inside of the TinyMCE Editor I get an error. This error comes from my backend where I first validate the request and then allow it to be processed.
This request fails because the image gets omitted as a base64 string inside of the src attribute inside of the <img> tag and the resulting string exceeds my max limit of 65535 characters.
Now strangely after that first unsuccessful attempt the src attribute wihtin the <img> tag has been replaced successfully with the location string from my backend and I now can save the form without a problem.
I will also provide my a snippet of my current TinyMCE setup. My current implementation is that the image is first added locally as a blob and then uploaded to the server when the user saves the form. After that, TinyMCE should automatically replace the src attribute with the appropriate location string.
My current implementation is as follows
const submit = (e) => {
e.preventDefault()
editorRef.current.uploadImages().then((uploadResults) => {
if (!memory) {
post(route('memory'), {
onSuccess: handleSuccess,
onError: (errors) => {
console.error(Object.values(errors))
handleError()
}
})
} else {
post(route('memory.update', { slug: memory.slug }), {
onSuccess: handleSuccess,
onError: (errors) => {
console.error(errors)
handleError()
}
})
}
})
}
const handleSuccess = () => {
toast({
title: <Check className="text-blue-500"/>,
description: !memory
? t('apiResponse.success.add')
: t('apiResponse.success.text'),
})
}
const handleError = () => {
toast({
title: t('apiResponse.error.title')
})
}
Is there something wrong with how I'm handling the Promise?
I am grateful for anyone's efforts to point me in the right direction. I have spent hours trying to fix this problem. I just can't seem to get behind it.
If you need additional context, please ask. I'm more than happy to provide it.
I have already tried setting the state of body manually and replacing the base64 string with the url from the promise result
async function uploadImages() {
const results = await editorRef.current.uploadImages();
const body= data.body; // Create a copy of the state
for (const result of results) {
if (result.status === true) {
const imageUrl = result.uploadUri;
updatedBody = updatedBody.replace(result.blobInfo.base64(), imageUrl);
}
}
setData('body', updatedBody);
return results.map(result => result.status === true);
}
and then using it like this:
const submit = async (e) => {
e.preventDefault();
try {
const uploadResults = await uploadImages();
if (uploadResults.every(value => value)) {
if (typeof memory === 'undefined') {
post(route('memory'), { onSuccess: handleSuccess });
} else {
patch(route('memory.update', { slug: memory.slug }), { onSuccess: handleSuccess });
}
} else {
toast({ title: t('apiResponse.error.title') });
}
} catch (error) {
console.error('Error during image uploads:', error);
}
};
Here is my TinyMCE implementation:
<Editor
init={{
file_picker_types: 'image',
relative_urls: false,
remove_script_host: false,
document_base_url: '../',
images_upload_handler: handleImageUpload,
images_upload_url: route('file.store'),
automatic_uploads: false,
}}
/>
const handleImageUpload = (blobInfo, progress) => new Promise((resolve, reject) => {
const formData = new FormData()
formData.append('file', blobInfo.blob())
axios.post(route('file.store'), formData, {
onUploadProgress: ({loaded, total}) => {
progress(Math.round((loaded * 100) / total))
},
withXSRFToken: true,
}).then((response) => {
const { location } = response.data
resolve(location)
}).catch((error) => {
console.error('Error:', error)
reject(error.response.data.location)
})
})
✔️ Expected result
The src attribute gets replaced before the form is submitted.
❌ Actual result
The form gets omitted with the blob URI still in the src attribute.
📃 Other details
- Browser: Opera GX
- OS: Windows 10
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
- Ngôn ngữ chính
- TypeScript
- Star
- 1.1k
- Fork
- 167
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tinymce/tinymce-react
-
status: escalated
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
tinymce/tinymce-react#617 ·
-
smart_paste doesn't detected pasted urls as linkCó thể đã có người làm @hardikpedia đã nhận 50 ngày trước. Đang mởstatus: escalated
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
tinymce/tinymce-react#611 · 1 bình luận ·
-
needs: more info
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
tinymce/tinymce-react#595 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
tinymce/tinymce-react#587 · 15 bình luận · 3 reaction ·
-
bug GitHub status: escalated
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
tinymce/tinymce-react#403 · 5 bình luận · 1 reaction ·
Tất cả issue của tinymce/tinymce-react
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zabuton-app/meguri#875 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
iruzen-dono/workless#117 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:api area:web wave wave:trivial
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
vetro-protocol/vetro-monorepo#1321 ·
Maintainer thường phản hồi trong vòng 1 ngày