Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图片上传问题 #2945

Closed
betwowt opened this issue Dec 14, 2022 · 17 comments · Fixed by halo-dev/plugin-s3#11
Closed

图片上传问题 #2945

betwowt opened this issue Dec 14, 2022 · 17 comments · Fixed by halo-dev/plugin-s3#11
Assignees
Labels
area/console Issues or PRs related to the Halo Console area/plugin Issues or PRs related to the Plugin Provider kind/bug Categorizes issue or PR as related to a bug. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now.
Milestone

Comments

@betwowt
Copy link

betwowt commented Dec 14, 2022

是什么版本出现了此问题?

v2.0.1

使用的什么数据库?

PostgreSQL

使用的哪种方式部署?

Docker

在线站点地址

No response

发生了什么?

使用阿里云oss插件,通过粘贴板先后粘贴三张图片上传,实际结果只有一张图片被上传了,可能原因是三张图片默认粘贴到系统都叫image.png
image
image
image

相关日志输出

No response

附加信息

No response

@ruibaby
Copy link
Member

ruibaby commented Dec 14, 2022

没能复现,我这边甚至无法粘贴。你使用的操作系统是?

/triage needs-information

@f2c-ci-robot f2c-ci-robot bot added the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 14, 2022
@betwowt
Copy link
Author

betwowt commented Dec 14, 2022

macos monterey
m1 芯片

@JohnNiang
Copy link
Member

本地上传也有类似的问题:

image

上传的表单详情如下:

-----------------------------330239117212975919733627836481
Content-Disposition: form-data; name="policyName"

default-policy
-----------------------------330239117212975919733627836481
Content-Disposition: form-data; name="groupName"


-----------------------------330239117212975919733627836481
Content-Disposition: form-data; name="file"; filename="image.png"
Content-Type: image/png

@longjuan
Copy link
Member

longjuan commented Jan 9, 2023

可能原因是三张图片默认粘贴到系统都叫image.png

本地存储的已经在#3042 中修复了
https://github.com/halo-sigs/plugin-aliosshttps://github.com/halo-sigs/plugin-s3 都没有对同名文件进行处理,导致同名文件只保留第一张或最后一张

这个问题可以通过先headobject查看是否存在同名文件,若同名可与本地存储一样报同名文件已存在错误
另外需不需要增加文件重命名功能,类似:
image
@JohnNiang @ruibaby

@JohnNiang
Copy link
Member

Hi @longjuan

IMO,建议暂时和本地上传的逻辑保持一致,通过 S3 上传的图片判断一下 object name 是否重复,如果重复则友好提示用户即可。

@longjuan
Copy link
Member

longjuan commented Jan 9, 2023

IMO,建议暂时和本地上传的逻辑保持一致,通过 S3 上传的图片判断一下 object name 是否重复,如果重复则友好提示用户即可。

好的
/assign

@JohnNiang
Copy link
Member

Hi @longjuan ,这个问题还需要在 console 端的上传组件还需要优化一下,对于直接粘贴的图片,需要用 $UUID.png 替换 image.png

@JohnNiang
Copy link
Member

/kind bug
/area console
/area plugin
/remove-triage needs-information

@f2c-ci-robot f2c-ci-robot bot added kind/bug Categorizes issue or PR as related to a bug. area/console Issues or PRs related to the Halo Console area/plugin Issues or PRs related to the Plugin Provider and removed triage/needs-information Indicates an issue needs more information in order to work on it. labels Jan 10, 2023
@longjuan
Copy link
Member

Hi @longjuan ,这个问题还需要在 console 端的上传组件还需要优化一下,对于直接粘贴的图片,需要用 $UUID.png 替换 image.png

好的,我研究一下

@longjuan
Copy link
Member

longjuan commented Jan 11, 2023

Hi @longjuan ,这个问题还需要在 console 端的上传组件还需要优化一下,对于直接粘贴的图片,需要用 $UUID.png 替换 image.png

我看了一下,被命名为image.png似乎是浏览器行为。
在截图后或者其他地方复制一张图片(非本地文件),粘贴到uppy,捕获paste事件发现他name就是image.png
image

而在Firefox中会被命名为图片.png
image

在复制本地文件然后粘贴时,name就是本地文件名
image

我想不到有什么好的办法处理不同浏览器的行为,大佬来看看吧 @ruibaby

不知道Safari又会命名成什么

@ruibaby
Copy link
Member

ruibaby commented Jan 11, 2023

我想不到有什么好的办法处理不同浏览器的行为,大佬来看看吧 @ruibaby

OK,我会抽时间研究一下。

/assign

f2c-ci-robot bot pushed a commit to halo-dev/plugin-s3 that referenced this issue Jan 28, 2023
Fixes halo-dev/halo#2945
```release-note
Add file check with the same name when uploading
```

我这里使用了ConcurrentHashMap避免**同时**上传两个同名文件导致文件覆盖问题,在本地存储策略中是由操作系统保证的
不知道这样是不是一个好方法

S3AsyncClient中没有`doesObjectExist`类似的方法,官方的文档也让用`headObject`捕获异常的办法来判断文件是否存在,详见https://github.com/aws/aws-sdk-java-v2/blob/master/docs/LaunchChangelog.md 中搜索`doesObjectExist`
@JohnNiang
Copy link
Member

可能还是得在后端兼容同名的附件上传。无论是本地上传还是 OSS 上传。

@longjuan
Copy link
Member

longjuan commented Feb 1, 2023

可能还是得在后端兼容同名的附件上传。无论是本地上传还是 OSS 上传。

什么策略,全部都要重命名还是重复了才重命名,是拼接时间戳吗?

@ruibaby ruibaby added this to the 2.3.x milestone Feb 4, 2023
@lixuejun725
Copy link

项目同样遇到这样的问题,这边觉得可以加上时间戳,毕竟是复制上来的附件一般只在本篇文章使用。复用率很低

@ruibaby ruibaby added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Feb 7, 2023
@ruibaby
Copy link
Member

ruibaby commented Feb 17, 2023

已经在 #3305 中支持自动重命名。

/close

@f2c-ci-robot f2c-ci-robot bot closed this as completed Feb 17, 2023
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Feb 17, 2023

@ruibaby: Closing this issue.

In response to this:

已经在 #3305 中支持自动重命名。

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ruibaby ruibaby modified the milestones: 2.3.x, 2.3.0 Feb 17, 2023
@huanglian666
Copy link

可以麻烦问一下,本地上传方式,上传的图片去哪里呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/console Issues or PRs related to the Halo Console area/plugin Issues or PRs related to the Plugin Provider kind/bug Categorizes issue or PR as related to a bug. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now.
Projects
None yet
6 participants