Skip to content

Commit

Permalink
Showing 6 changed files with 32 additions and 15 deletions.
25 changes: 16 additions & 9 deletions packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts
Original file line number Diff line number Diff line change
@@ -276,15 +276,21 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
signal,
}).abortOn(signal)) as unknown as B // todo this doesn't make sense

// location will be missing from result if CORS is not correctly set up on the bucket.
return 'location' in result ? result : (
{
// todo `url` is not really the final location URL of the resulting file, it's just the base URL of the bucket
// https://github.com/transloadit/uppy/issues/5388
location: removeMetadataFromURL(url),
...result,
}
const key = fields?.key
if (!key) {
console.error(

Check warning on line 281 in packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts

GitHub Actions / Lint JavaScript/TypeScript

Unexpected console statement
'Expected `fields.key` to be returend but the backend/Companion',
)
}
this.#setS3MultipartState(file, { key: key! })

return {
...result,
location:
(result.location as string | undefined) ?? removeMetadataFromURL(url),
bucket: fields?.bucket,
key,
}
}

async uploadFile(
@@ -393,7 +399,8 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {

try {
signature = await this.#fetchSignature(this.#getFile(file), {
uploadId,
// Always defined for multipart uploads
uploadId: uploadId!,
key,
partNumber,
body: chunkData,
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3/src/MultipartUploader.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ interface MultipartUploaderOptions<M extends Meta, B extends Body> {
file: UppyFile<M, B>
log: Uppy<M, B>['log']

uploadId: string
uploadId?: string
key: string
}

7 changes: 6 additions & 1 deletion packages/@uppy/aws-s3/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -50,7 +50,10 @@ describe('AwsS3Multipart', () => {
getUploadParameters: () => ({
method: 'POST',
url: 'https://bucket.s3.us-east-2.amazonaws.com/',
fields: {},
fields: {
key: 'file',
bucket: 'https://bucket.s3.us-east-2.amazonaws.com/',
},
}),
})
const scope = nock(
@@ -89,6 +92,8 @@ describe('AwsS3Multipart', () => {
ETag: 'test',
etag: 'test',
location: 'http://example.com',
key: 'file',
bucket: 'https://bucket.s3.us-east-2.amazonaws.com/',
},
status: 200,
uploadURL: 'http://example.com',
6 changes: 3 additions & 3 deletions packages/@uppy/aws-s3/src/index.ts
Original file line number Diff line number Diff line change
@@ -510,7 +510,7 @@ export default class AwsS3Multipart<
return this.#client
.get<
AwsS3Part[]
>(`s3/multipart/${encodeURIComponent(uploadId)}?key=${filename}`, { signal })
>(`s3/multipart/${encodeURIComponent(uploadId!)}?key=${filename}`, { signal })
.then(assertServerError)
}

@@ -524,7 +524,7 @@ export default class AwsS3Multipart<
throwIfAborted(signal)

const filename = encodeURIComponent(key)
const uploadIdEnc = encodeURIComponent(uploadId)
const uploadIdEnc = encodeURIComponent(uploadId!)
return this.#client
.post<B>(
`s3/multipart/${uploadIdEnc}/complete?key=${filename}`,
@@ -633,7 +633,7 @@ export default class AwsS3Multipart<
this.#assertHost('abortMultipartUpload')

const filename = encodeURIComponent(key)
const uploadIdEnc = encodeURIComponent(uploadId)
const uploadIdEnc = encodeURIComponent(uploadId!)
return this.#client
.delete<void>(`s3/multipart/${uploadIdEnc}?key=${filename}`, undefined, {
signal,
4 changes: 3 additions & 1 deletion packages/@uppy/aws-s3/src/utils.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ export function throwIfAborted(signal?: AbortSignal | null): void {
}
}

export type UploadResult = { key: string; uploadId: string }
export type UploadResult = { key: string; uploadId?: string; bucket?: string }
export type UploadResultWithSignal = UploadResult & { signal?: AbortSignal }
export type MultipartUploadResult = UploadResult & { parts: AwsS3Part[] }
export type MultipartUploadResultWithSignal = MultipartUploadResult & {
@@ -25,4 +25,6 @@ export type UploadPartBytesResult = {

export interface AwsBody extends Body {
location: string
key: string
bucket: string
}
3 changes: 3 additions & 0 deletions packages/@uppy/companion/src/server/controllers/s3.js
Original file line number Diff line number Diff line change
@@ -135,6 +135,7 @@ module.exports = function s3 (config) {
res.json({
key: data.Key,
uploadId: data.UploadId,
bucket: data.Bucket
})
}, next)
}
@@ -360,6 +361,8 @@ module.exports = function s3 (config) {
})).then(data => {
res.json({
location: data.Location,
key: data.Key,
bucket: data.Bucket
})
}, next)
}

0 comments on commit 45aecae

Please sign in to comment.