Skip to content

Commit 8cb65bb

Browse files
authored
@uppy/aws-s3: clarify and warn when incorrect buckets settings are used (#5505)
#5388 (comment)
1 parent 014f1da commit 8cb65bb

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

docs/uploader/aws-s3-multipart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The configuration required for Uppy and Companion is this:
101101
[
102102
{
103103
"AllowedOrigins": ["https://my-app.com"],
104-
"AllowedMethods": ["GET", "PUT"],
104+
"AllowedMethods": ["GET", "PUT", "POST"],
105105
"MaxAgeSeconds": 3000,
106106
"AllowedHeaders": [
107107
"Authorization",

packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
242242
file: UppyFile<M, B>,
243243
chunk: Chunk,
244244
signal?: AbortSignal,
245-
): Promise<UploadPartBytesResult & B> {
245+
) {
246246
const {
247247
method = 'POST',
248248
url,
@@ -252,7 +252,7 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
252252
signal,
253253
}).abortOn(signal)
254254

255-
let body
255+
let body: FormData | Blob
256256
const data = chunk.getData()
257257
if (method.toUpperCase() === 'POST') {
258258
const formData = new FormData()
@@ -267,21 +267,24 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
267267

268268
const { onProgress, onComplete } = chunk
269269

270-
const result = await this.#uploadPartBytes({
270+
const result = (await this.#uploadPartBytes({
271271
signature: { url, headers, method } as any,
272272
body,
273273
size: data.size,
274274
onProgress,
275275
onComplete,
276276
signal,
277-
}).abortOn(signal)
277+
}).abortOn(signal)) as unknown as B // todo this doesn't make sense
278278

279-
return 'location' in result ?
280-
(result as UploadPartBytesResult & B)
281-
: ({
279+
// location will be missing from result if CORS is not correctly set up on the bucket.
280+
return 'location' in result ? result : (
281+
{
282+
// todo `url` is not really the final location URL of the resulting file, it's just the base URL of the bucket
283+
// https://github.com/transloadit/uppy/issues/5388
282284
location: removeMetadataFromURL(url),
283285
...result,
284-
} as any)
286+
}
287+
)
285288
}
286289

287290
async uploadFile(

packages/@uppy/aws-s3/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,14 +760,14 @@ export default class AwsS3Multipart<
760760
}
761761
const { etag, location } = headersMap
762762

763-
if (method.toUpperCase() === 'POST' && location === null) {
763+
if (method.toUpperCase() === 'POST' && location == null) {
764764
// Not being able to read the Location header is not a fatal error.
765765
// eslint-disable-next-line no-console
766766
console.warn(
767767
'AwsS3/Multipart: Could not read the Location header. This likely means CORS is not configured correctly on the S3 Bucket. See https://uppy.io/docs/aws-s3-multipart#S3-Bucket-Configuration for instructions.',
768768
)
769769
}
770-
if (etag === null) {
770+
if (etag == null) {
771771
reject(
772772
new Error(
773773
'AwsS3/Multipart: Could not read the ETag header. This likely means CORS is not configured correctly on the S3 Bucket. See https://uppy.io/docs/aws-s3-multipart#S3-Bucket-Configuration for instructions.',

0 commit comments

Comments
 (0)