Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Refactor image upload method to client-side download (#14)
Browse files Browse the repository at this point in the history
重构图片上传的方案,改为先在客户端下载,然后调用上传文件的接口上传到附件。

此改动主要考虑到服务器网络环境问题,可能在服务器无法访问 Unsplash 服务或者速度缓慢。

/kind improvement

```release-note
重构图片上传的方案,改为先在客户端下载,然后调用上传文件的接口上传到附件。
```
  • Loading branch information
ruibaby authored Sep 14, 2024
1 parent 8359b76 commit d94d90a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions console/src/components/UnsplashSelectorProvider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,19 @@ async function downloadSinglePhoto(photo: Photo) {
try {
const { policyName, groupName, urlType } = basicConfig.value?.downloadMode || {}
const { data: newAttachment } = await axiosInstance.post<Attachment>(
`/apis/api.console.halo.run/v1alpha1/attachments/-/upload-from-url`,
{
url: photo.urls[urlType || 'raw'],
filename: `${photo.alt_description?.toLowerCase().replace(/\s+/g, '-') || photo.id}.jpg`,
policyName: policyName,
groupName: groupName
}
)
const imageResponse = await fetch(photo.urls[urlType || 'raw'])
const imageBlob = await imageResponse.blob()
const { data: newAttachment } = await consoleApiClient.storage.attachment.uploadAttachment({
file: new File(
[imageBlob],
`${photo.alt_description?.toLowerCase().replace(/\s+/g, '-') || photo.id}.jpg`,
{ type: imageBlob.type }
),
policyName: policyName as string,
groupName: groupName
})
await bindingAttachmentMutate({
attachment: newAttachment,
Expand Down

0 comments on commit d94d90a

Please sign in to comment.