Skip to content

Commit

Permalink
Revert "feat: s3 multipart upload"
Browse files Browse the repository at this point in the history
This reverts commit 157f45f765d46d7360fd4fa099e56d235084b7b4.
  • Loading branch information
clothe09986 committed Nov 24, 2023
1 parent c3d8610 commit aa8767e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 67 deletions.
68 changes: 2 additions & 66 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const validateImage = (file: RcFile, fileSize?: number) => {
return isImage && inSize
}

export const uploadFileOld = async (key: string, file: Blob, authToken: string | null, config?: AxiosRequestConfig) =>
export const uploadFile = async (key: string, file: Blob, authToken: string | null, config?: AxiosRequestConfig) =>
await axios
.post(
`${process.env.REACT_APP_API_BASE_ROOT}/sys/sign-url`,
Expand All @@ -45,7 +45,7 @@ export const uploadFileOld = async (key: string, file: Blob, authToken: string |
.then(res => res.data.result)
.then(url => {
const { query } = queryString.parseUrl(url)
const a = axios.put<{ status: number; data: string }>(url, file, {
return axios.put<{ status: number; data: string }>(url, file, {
...config,
headers: {
...query,
Expand All @@ -54,70 +54,6 @@ export const uploadFileOld = async (key: string, file: Blob, authToken: string |
})
})

export const uploadFile = async (key: string, file: Blob, authToken: string | null, config?: AxiosRequestConfig) => {
if (!file) {
throw new Error('no file')
}
try {
const createResponse = await axios.post(
`${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}/storage/multipart/create`,
{
params: { Key: key, type: file.type },
},
{
headers: { authorization: `Bearer ${authToken}` },
},
)
const { uploadId } = createResponse.data

const PART_SIZE = 5 * 1024 * 1024 // 5MB
const { size } = file
const partCount = Math.max(Math.ceil(size / PART_SIZE), 1)
let parts = []

for (let partNumber = 1; partNumber <= partCount; partNumber++) {
const start = (partNumber - 1) * PART_SIZE
const end = partNumber * PART_SIZE

const presignResponse = await axios.post(
`${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}/storage/multipart/sign-url`,
{
params: { Key: key, UploadId: uploadId, PartNumber: partNumber },
},
{
headers: { authorization: `Bearer ${authToken}` },
},
)
const { presignedUrl } = presignResponse.data

const uploadResponse = await axios.put(presignedUrl, file.slice(start, end), {
...config,
headers: {
'Content-Type': file.type,
},
})
parts.push({
ETag: `${uploadResponse.headers.etag}`,
PartNumber: partNumber,
})
}

const completedUploadResponse = await axios.post(
`${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}/storage/multipart/complete`,
{
params: { Key: key, UploadId: uploadId, MultipartUpload: { Parts: parts } },
},
{
headers: { authorization: `Bearer ${authToken}` },
},
)
return { data: completedUploadResponse.data, status: completedUploadResponse.status }
} catch (error) {
console.log(error)
throw error
}
}

export const uploadFileV2 = async (
key: string,
file: Blob,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13959,7 +13959,7 @@ lodash.upperfirst@^4.3.1:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

lodestar-app-element@urfit-tech/lodestar-app-element#master:
lodestar-app-element@urfit-tech/lodestar-app-element#5618d2672b405edb3840bd28d4be27b2c6e80167:
version "0.1.0"
resolved "https://codeload.github.com/urfit-tech/lodestar-app-element/tar.gz/8cda736c5d040bb677f26ef9ad1fdcbb838cc2a2"
dependencies:
Expand Down

0 comments on commit aa8767e

Please sign in to comment.