MediBase Appointment Form Convenience Solution: Paste LINE / WhatsApp Image-Text Links, One-Click QR Code Upload
1. One-sentence solution
Users copy “QR code image + explanatory text + add-friend link” from chat tools such as LINE and WhatsApp, then paste it directly into the contact field of the MediBase booking form: the page retains the text and link, automatically extracts and uploads the QR code; after refreshing the page, unsubmitted content and the QR code status can still be restored.

The key is not to stuff the image into a single-line input box, but to split a mixed clipboard operation into three traceable pieces of data:
| Data | Frontend handling | Final use |
|---|---|---|
| Explanatory text | Normalize whitespace and write back to the contact field | For customer service to read |
| Add-friend link | Move to the beginning of the text and also write to a separate hidden field | Makes one-click friend adding easier |
| QR code image | Extract during the original paste event and upload directly to private storage | As a contact attachment |
This design applies to contact methods that support QR codes, such as LINE, WhatsApp, KakaoTalk, and WeChat. WeChat does not assume that a copyable add-friend link exists; the interface instead prompts users to save the QR code first, then copy and paste it or select it for upload.
2. Actual user experience
- Copy the QR code image-and-text share content in the chat tool.
- Select the corresponding contact method on the booking page and paste.
- The link is automatically moved to the front, explanatory text is retained; upload starts immediately when an image is detected.
- The page indicates that the QR code has been temporarily saved; the user can continue filling out the form or refresh the page.
- At formal submission, the backend rechecks the object's authenticity before binding the QR code to the booking.
When there is no image, the browser denies clipboard permission, or the image format is unsupported, pasting of text and links is not affected; users can still use the regular upload entry to upload the QR code separately.
3. Frontend core: get the image first, then process the text
Why timing determines success or failure
Some LINE / WhatsApp clients expose images only during the browser's original paste event and while the user gesture is still valid. If you rewrite the input box or call preventDefault() first and then read the clipboard, the image data or Clipboard API permission may already be invalid.
Therefore, the first statement of the listener must start reading the image; text normalization, preventing the default paste, and draft saving come afterward.
contact.addEventListener('paste', function (event) {
var clip = event.clipboardData;
if (!clip) return;
// 保持在原始 paste / 用户手势上下文内启动图片读取。
var imagePromise = clipboardQrImage(clip);
var text = clip.getData('text/plain') || '';
var found = text.match(/https?:\/\/[^\s<>"']+/i);
if (text !== '') {
event.preventDefault();
var rest = found ? text.replace(found[0], '').replace(/\s+/g, ' ').trim() : '';
contact.value = found
? found[0] + (rest === '' ? '' : ' ' + rest)
: text.replace(/\s+/g, ' ');
saveLocalDraft(); // 脚本赋值不会触发 input,需立即保存。
}
if (friend && found) friend.value = found[0];
imagePromise.then(function (image) {
if (image) return upload(image);
}).catch(function () {});
});
The product result of this logic is: the single-line input box prioritizes displaying the most valuable link, customer service can still see supplementary notes, and the QR code enters an independent, validated upload pipeline.
Four-layer compatibility strategy for image extraction
Different browsers and chat clients provide different clipboard structures; try them in order of success rate and reliability:
clipboardData.files: directly obtain image files such as PNG/JPG.clipboardData.items: retrieve the file fromClipboardItem.text/html: only parse inline images in<img src="data:image/...">.navigator.clipboard.read(): use as the final fallback within the user gesture.
function clipboardQrImage(clip) {
for (var i = 0; i < (clip.files || []).length; i++) {
if (/^image\//i.test(clip.files[i].type || '')) return Promise.resolve(clip.files[i]);
}
for (var j = 0; j < (clip.items || []).length; j++) {
var item = clip.items[j];
if (item.kind === 'file' && /^image\//i.test(item.type || '')) {
var file = item.getAsFile();
if (file) return Promise.resolve(file);
}
}
// 只允许内嵌 data URI,绝不替用户抓取任意外链图片。
var html = clip.getData('text/html') || '';
var match = html.match(/<img\b[^>]*\bsrc\s*=\s*(['"])(data:image\/(?:jpeg|png|webp|gif)(?:;base64)?,[^'"]+)\1/i);
if (match) return fetch(match[2]).then(function (r) { return r.blob(); });
return browserClipboardQrImage();
}
Only JPEG, PNG, WebP, and GIF are accepted. The HTML fallback only handles inline data URIs, which both avoids server-side fetching of external links and avoids turning the user's clipboard into a covert entry point for network requests.
4. Frontend upload and draft recovery
Image bytes are not submitted with the booking form. The browser first requests a one-time upload ticket, then uploads directly to a private object; the page keeps only the object identifier, MIME, original file name, and byte count.
粘贴 / 选择图片
→ 申请单对象上传票据
→ 浏览器直传私有对象
→ 写入对象元数据和本机草稿
→ 正式提交时后端复核对象
→ 成功后认领为该预约的附件
After a successful upload, the frontend immediately writes the QR code metadata and Other named fields into the same-browser draft. During recovery, it does not attempt to restore file input fields that browsers prohibit repopulating; instead, it restores the uploaded object identifier and displays the success status; final submission can reuse that object without uploading again.
The draft is only a convenience layer: recovery is not promised after clearing site data, in incognito mode, or when switching browsers or devices. After successful submission, the local draft corresponding to that booking path should be cleared to avoid accidentally carrying it into the next booking.
5. Key backend logic: the client cannot have the final say on the object
The backend does not receive the QR code's multipart body and never trusts a QR code URL submitted by the client. It only issues restricted direct-upload tickets; when the booking is submitted, it uses the object identifier provided by the client to recheck the object location, declared MIME, size, and actual file header.
function attachQr(string $key, string $mime, string $name, int $bytes): array {
if (!validKeyForPrivateQrScope($key, $mime) || $bytes < 1 || $bytes > maxBytes()) {
throw new RuntimeException('二维码上传信息不合法,请重新选择图片');
}
if (!matchesImageHeader(peekObjectHeader($key), $mime)) {
throw new RuntimeException('二维码真实格式与上传格式不一致,请重新选择图片');
}
recordPrivateAttachment([
'key' => $key,
'original_name' => safeName($name),
'bytes' => $bytes,
'mime' => $mime,
]);
return ['key' => $key, 'url' => privateObjectUrl($key)];
}
Authenticity verification covers at least:
- The object identifier must match the QR-code-specific private directory and random naming format;
- The MIME must be within the JPEG, PNG, WebP, GIF whitelist;
- The size must be within the allowed range;
- The object header must match the declared MIME, such as the PNG signature, JPEG start bytes, GIF version header, or WebP RIFF header;
- The original file name must sanitize path fragments and be length-limited.
This avoids issues such as forging external URLs, referencing objects across purposes, changing extensions to impersonate images, and untrusted file names.
Submission and claiming are two steps
The key order for booking submission is as follows:
$qr = attachQr($submittedKey, $submittedMime, $submittedName, $submittedBytes);
$input['contact_qr_url'] = $qr['url'];
$input['contact_qr_key'] = $qr['key'];
validateBooking($input); // 联系方式文本或已验证二维码至少存在其一
$booking = createBooking($input); // 先持久化预约主体
claimAttachment($qr['key'], $booking['id']); // 再绑定附件归属
The draft stage likewise verifies whether the object exists, whether the scope is correct, and whether the header matches, but does not claim the attachment; it is claimed only after the formal booking is successfully created. This supports refresh recovery while preventing temporary uploaded objects from becoming formal business attachments prematurely.
6. Copy and caching
The frontend obtains the prompt copy for the current language through page data attributes and only performs {channel} placeholder replacement. Simplified Chinese, Traditional Chinese, English, Japanese, and Korean should maintain all three types of copy: general image-and-text paste prompt, WeChat-specific prompt, and upload success prompt.
Static assets are output with a version marker based on content updates, ensuring that after deploying new scripts or styles, browsers and CDNs do not continue to hit old resources. Do not hand-write asset URLs without version markers.
7. Acceptance checklist
- Image-and-text paste from LINE and WhatsApp can retain the link, explanatory text, and QR code at the same time.
- When only an image is pasted, it uploads automatically; when only text or a link is pasted, no upload error is reported.
- When the Clipboard API is unsupported, the user denies permission, or the image cannot be extracted, text pasting still works normally.
- WeChat displays the specific prompt “Save the image, then copy and paste or upload it.”
- Refresh after upload: the contact method, add-friend link, uploaded QR code status, and Other filled fields can be restored.
- Tampering with the object identifier, MIME, size, or forging image content before formal submission is rejected.
- After the booking is completed, attachment ownership is correct; draft objects are not claimed prematurely.
- The channel names and prompt copy in all five page languages are correct.
8. Security boundaries
- Do not fetch or proxy arbitrary clipboard external-link images; accept only images exposed by the current user action or inline data URIs.
- Direct upload of private objects does not mean trusting the client: the object's true identity must be re-verified at submission.
- Clipboard read failures must degrade silently and must not block users from filling in contact information.
- Do not record the original QR code image, personal contact information, or user-identifiable information in logs, test data, or comments.
9. Test plan: using lumiin Dermatology booking submission as an example
Open the lumiin Dermatology booking URL: https://lumiin.medibase.clinic/booking
Switch to WhatsApp or LINE as the contact method, then paste into the input box the copied content from either of these contact methods.

10. About MediBase
MediBase is an information and connection platform for healthcare service decision-making. Medi comes from Medical and Medicine, representing respect for medical expertise, clinical information, and health needs; Base means cornerstone, foundation, base, and infrastructure, representing stable and trustworthy data, services, and connection capabilities.
The brand believes that when users seek healthcare services, what they need is not more information that is hard to verify, but a clearer path of choices: where this institution is, what services it provides, how to understand prices, whether there is a suitable doctor, and how to communicate and complete a booking. MediBase organizes institution, doctor, treatment item, price, review, case, and booking information around these practical questions, enabling users to move from learning and comparing to contacting the institution and completing a more coherent decision-making process.