Skip to content

Commit

Permalink
Merge pull request #6 from narol1024/delevop
Browse files Browse the repository at this point in the history
fix: http -> https when uploading completed
  • Loading branch information
narol1024 authored May 26, 2024
2 parents a912324 + 96ed04b commit 538d91f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/util/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ export async function uploadFileOnAliCloudOSS(file: File): Promise<{
bucket: "mortal-app",
region: "oss-cn-beijing",
});

const fileName = `${getRandomString(6)}_${new Date().getTime()}`;
const fileType = file.type;
if (!fileType.includes("image/")) {
return Promise.reject(new Error("File is not a image type"));
}
const fileName = `${getRandomString(6)}_${new Date().getTime()}.${fileType
.split("/")
.pop()}`;
const result = await client.put(`pictures/${fileName}`, file);
if (result.res.status === 200) {
return Promise.resolve({
url: result.url,
url: result.url.replace("http", "https"),
});
}
return Promise.reject(new Error("Failed to upload file"));
Expand Down

0 comments on commit 538d91f

Please sign in to comment.