Add attachment previews and data URLs for drops
This commit is contained in:
@@ -722,7 +722,7 @@ export default function PromptInput(props: PromptInputProps) {
|
||||
|
||||
const createAndStoreAttachment = (previewUrl?: string) => {
|
||||
const attachment = createFileAttachment(path, filename, mime, undefined, props.instanceFolder)
|
||||
if (previewUrl && mime.startsWith("image/")) {
|
||||
if (previewUrl && (mime.startsWith("image/") || mime.startsWith("text/"))) {
|
||||
attachment.url = previewUrl
|
||||
}
|
||||
addAttachment(props.instanceId, props.sessionId, attachment)
|
||||
@@ -735,6 +735,13 @@ export default function PromptInput(props: PromptInputProps) {
|
||||
createAndStoreAttachment(result)
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
} else if (mime.startsWith("text/") && typeof FileReader !== "undefined") {
|
||||
const reader = new FileReader()
|
||||
reader.onload = () => {
|
||||
const dataUrl = typeof reader.result === "string" ? reader.result : undefined
|
||||
createAndStoreAttachment(dataUrl)
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
} else {
|
||||
createAndStoreAttachment()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user