mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-21 01:15:35 +00:00
@uppy/aws-s3: clarify and warn when incorrect buckets settings are used (#5505)
https://github.com/transloadit/uppy/issues/5388#issuecomment-2464885562
This commit is contained in:
parent
014f1da0e5
commit
8cb65bb223
3 changed files with 14 additions and 11 deletions
|
|
@ -101,7 +101,7 @@ The configuration required for Uppy and Companion is this:
|
|||
[
|
||||
{
|
||||
"AllowedOrigins": ["https://my-app.com"],
|
||||
"AllowedMethods": ["GET", "PUT"],
|
||||
"AllowedMethods": ["GET", "PUT", "POST"],
|
||||
"MaxAgeSeconds": 3000,
|
||||
"AllowedHeaders": [
|
||||
"Authorization",
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
|
|||
file: UppyFile<M, B>,
|
||||
chunk: Chunk,
|
||||
signal?: AbortSignal,
|
||||
): Promise<UploadPartBytesResult & B> {
|
||||
) {
|
||||
const {
|
||||
method = 'POST',
|
||||
url,
|
||||
|
|
@ -252,7 +252,7 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
|
|||
signal,
|
||||
}).abortOn(signal)
|
||||
|
||||
let body
|
||||
let body: FormData | Blob
|
||||
const data = chunk.getData()
|
||||
if (method.toUpperCase() === 'POST') {
|
||||
const formData = new FormData()
|
||||
|
|
@ -267,21 +267,24 @@ export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
|
|||
|
||||
const { onProgress, onComplete } = chunk
|
||||
|
||||
const result = await this.#uploadPartBytes({
|
||||
const result = (await this.#uploadPartBytes({
|
||||
signature: { url, headers, method } as any,
|
||||
body,
|
||||
size: data.size,
|
||||
onProgress,
|
||||
onComplete,
|
||||
signal,
|
||||
}).abortOn(signal)
|
||||
}).abortOn(signal)) as unknown as B // todo this doesn't make sense
|
||||
|
||||
return 'location' in result ?
|
||||
(result as UploadPartBytesResult & B)
|
||||
: ({
|
||||
// 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,
|
||||
} as any)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async uploadFile(
|
||||
|
|
|
|||
|
|
@ -760,14 +760,14 @@ export default class AwsS3Multipart<
|
|||
}
|
||||
const { etag, location } = headersMap
|
||||
|
||||
if (method.toUpperCase() === 'POST' && location === null) {
|
||||
if (method.toUpperCase() === 'POST' && location == null) {
|
||||
// Not being able to read the Location header is not a fatal error.
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
'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.',
|
||||
)
|
||||
}
|
||||
if (etag === null) {
|
||||
if (etag == null) {
|
||||
reject(
|
||||
new Error(
|
||||
'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.',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue