Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: png avatar upload as jpeg (#8665)

非法操作b37954b96610
diff --git a/web/app/components/base/app-icon-picker/index.tsx b/web/app/components/base/app-icon-picker/index.tsx
index 82548154750..ba375abdd9c 100644
--- a/web/app/components/base/app-icon-picker/index.tsx
+++ b/web/app/components/base/app-icon-picker/index.tsx
@@ -88,7 +88,7 @@ const AppIconPicker: FC<AppIconPickerProps> = ({
if (!imageCropInfo)
return
setUploading(true)
- const blob = await getCroppedImg(imageCropInfo.tempUrl, imageCropInfo.croppedAreaPixels)
+ const blob = await getCroppedImg(imageCropInfo.tempUrl, imageCropInfo.croppedAreaPixels, imageCropInfo.fileName)
const file = new File([blob], imageCropInfo.fileName, { type: blob.type })
handleLocalFileUpload(file)
}
diff --git a/web/app/components/base/app-icon-picker/utils.ts b/web/app/components/base/app-icon-picker/utils.ts
index 0c90e96febd..14c9ae3f289 100644
--- a/web/app/components/base/app-icon-picker/utils.ts
+++ b/web/app/components/base/app-icon-picker/utils.ts
@@ -11,6 +11,23 @@ export function getRadianAngle(degreeValue: number) {
return (degreeValue * Math.PI) / 180
}
+export function getMimeType(fileName: string): string {
+ const extension = fileName.split('.').pop()?.toLowerCase()
+ switch (extension) {
+ case 'png':
+ return 'image/png'
+ case 'jpg':
+ case 'jpeg':
+ return 'image/jpeg'
+ case 'gif':
+ return 'image/gif'
+ case 'webp':
+ return 'image/webp'
+ default:
+ return 'image/jpeg'
+ }
+}
+
/**
* Returns the new bounding area of a rotated rectangle.
*/
@@ -31,12 +48,14 @@ export function rotateSize(width: number, height: number, rotation: number) {
export default async function getCroppedImg(
imageSrc: string,
pixelCrop: { x: number; y: number; width: number; height: number },
+ fileName: string,
rotation = 0,
flip = { horizontal: false, vertical: false },
): Promise<Blob> {
const image = await createImage(imageSrc)
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
+ const mimeType = getMimeType(fileName)
if (!ctx)
throw new Error('Could not create a canvas context')
@@ -93,6 +112,6 @@ export default async function getCroppedImg(
resolve(file)
else
reject(new Error('Could not create a blob'))
- }, 'image/jpeg')
+ }, mimeType)
})
}