-
Notifications
You must be signed in to change notification settings - Fork 616
feat(lib-storage): rewrite lib-storage upload #2039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3242b18
fix: proper dependencies and node/browser configuration
alexforsyth 7d491d9
feat: adding example code for upload usage
alexforsyth 0bcbfc2
feat: export upload and upload types
alexforsyth 4201280
fix: example code imports the @aws-sdk/lib-storage package
alexforsyth 49e3806
add tests for upload
alexforsyth 143315b
feat: rewrite functions that get chunks of buffers, readable, and rea…
alexforsyth b745226
feat: add chunker wrapper that properly sends data to the correct chu…
alexforsyth e6d0ff6
feat: add upload types
alexforsyth 327cc7c
feat: add main uploader that manages multipart upload steps
alexforsyth 360c530
feat: add best attempt at getting the byte size of an object
alexforsyth ac5c199
fix: remove old files as part of rewrite
alexforsyth 7411756
Fix: add support for tags
alexforsyth 1561940
fix: only concat buffers when there is more than one buffer
alexforsyth d5f5a75
fix: resolve merge conflicts in already deleted files
alexforsyth d3722a1
fix: grammatical and naming fixes to address feedback
alexforsyth dca59a1
fix: correct the max number of parts s3 allows for multipart upload t…
alexforsyth e0ea40d
fix: use const in place of let
alexforsyth 2b5e682
fix: calling abort should throw abort error from upload
alexforsyth 12d44ae
fix: fully enumerate upload options on readme
alexforsyth 005b637
fix: throw error on abort
alexforsyth 3ce86b0
Merge branch 'rewrite-storage' of github.com:alexforsyth/aws-sdk-js-v…
alexforsyth 5c60662
fix: addressing PR feedback
alexforsyth 6bb5e7e
fix: manually ran prettier
alexforsyth 72e58f5
fix: nit single line branch
alexforsyth 05b6f8a
fix: remove unneeded add
alexforsyth 6fe4156
Fix: PR feedback
alexforsyth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const configuration = { | ||
Bucket: "test-bucket-1234567890", | ||
Key: `unique-key-${Date.now}`, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
import { Upload } from "../src/index"; | ||
import { Upload } from "@aws-sdk/lib-storage"; | ||
import { S3 } from "@aws-sdk/client-s3"; | ||
import { configuration } from "./config"; | ||
|
||
const fs = require("fs"); | ||
const fileStream = fs.createReadStream("./big.file"); | ||
const fileStream = fs.createReadStream(__dirname + "/big.file"); | ||
|
||
(async () => { | ||
const target = { | ||
Bucket: "aws-sdk-js-mock-files", | ||
Key: "data_key", | ||
Body: fileStream, | ||
}; | ||
const upload = new Upload({ | ||
params: { | ||
Bucket: configuration.Bucket, | ||
Key: configuration.Key, | ||
Body: fileStream, | ||
}, | ||
client: new S3({}), | ||
queueSize: 3, | ||
}); | ||
|
||
try { | ||
const upload = new Upload({ | ||
params: target, | ||
client: new S3({}), | ||
queueSize: 3, | ||
}); | ||
upload.on("httpUploadProgress", (progress) => { | ||
console.log(progress); | ||
}); | ||
|
||
upload.on("httpUploadProgress", (progress) => { | ||
console.log(progress); | ||
}); | ||
|
||
await upload.done(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
await upload.done(); | ||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { S3Client } from "@aws-sdk/client-s3"; | ||
import { Upload } from "@aws-sdk/lib-storage"; | ||
import { configuration } from "./config"; | ||
import { Readable } from "stream"; | ||
|
||
const Bucket = configuration.Bucket; | ||
const region = "us-west-2"; | ||
|
||
const sleep = async (seconds: number) => { | ||
return new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
}; | ||
|
||
async function* generateContents() { | ||
for (let index = 0; index < 8; index++) { | ||
const time = Math.random() * 5; | ||
await sleep(time); | ||
console.log(`Delaying part ${index} for ${time}`); | ||
yield `[Part ${index}] ${"#".repeat(2000000)}`; | ||
} | ||
} | ||
|
||
const uploadIndeterminateLengthStreamNode = async () => { | ||
const streamOfUnknownlength = Readable.from(generateContents()); | ||
|
||
const Key = configuration.Key; | ||
let upload = new Upload({ | ||
client: new S3Client({ region }), | ||
params: { | ||
Key, | ||
Bucket, | ||
Body: streamOfUnknownlength, | ||
}, | ||
}); | ||
|
||
upload.on("httpUploadProgress", (progress: ProgressEvent) => { | ||
console.log(progress); | ||
}); | ||
|
||
setTimeout(() => { | ||
console.log(" Aborting ...."); | ||
let res = upload.abort(); | ||
}, 10 * 1000); | ||
|
||
const uploadResult = await upload.done(); | ||
console.log("done uploading", uploadResult); | ||
}; | ||
|
||
uploadIndeterminateLengthStreamNode(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,22 @@ | ||
import { Upload } from "../src/index"; | ||
import { S3, S3Client } from "@aws-sdk/client-s3"; | ||
import { Upload } from "@aws-sdk/lib-storage"; | ||
import { S3 } from "@aws-sdk/client-s3"; | ||
import { configuration } from "./config"; | ||
|
||
const Bucket = "aws-sdk-js-mock-files"; | ||
const Key = "data_key"; | ||
const Bucket = configuration.Bucket; | ||
const Key = configuration.Key; | ||
const Body = | ||
"Duo Reges: constructio interrete. Qui autem esse poteris, nisi te amor ipse ceperit? Hoc est non modo cor non habere, sed ne palatum quidem. Quantam rem agas, ut Circeis qui habitet totum hunc mundum suum municipium esse existimet? Huius, Lyco, oratione locuples, rebus ipsis ielunior. Sed quid attinet de rebus tam apertis plura requirere? Non quam nostram quidem, inquit Pomponius iocans; Alterum significari idem, ut si diceretur, officia media omnia aut pleraque servantem vivere. Stoici scilicet"; | ||
|
||
(async () => { | ||
const target = { Bucket, Key, Body }; | ||
try { | ||
const paralellUploads3 = new Upload({ | ||
client: new S3({}), | ||
params: target, | ||
}); | ||
const paralellUploads3 = new Upload({ | ||
client: new S3({}), | ||
params: target, | ||
}); | ||
|
||
paralellUploads3.on("httpUploadProgress", (progress) => { | ||
console.log(progress); | ||
}); | ||
paralellUploads3.on("httpUploadProgress", (progress) => { | ||
console.log(progress); | ||
}); | ||
|
||
await paralellUploads3.done(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
|
||
try { | ||
const paralellUploads3Client = new Upload({ | ||
client: new S3Client({}), | ||
params: target, | ||
}); | ||
|
||
paralellUploads3Client.on("httpUploadProgress", (progress) => { | ||
console.log(progress); | ||
}); | ||
|
||
await paralellUploads3Client.done(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
await paralellUploads3.done(); | ||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity"; | ||
import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity"; | ||
|
||
import { S3Client } from "@aws-sdk/client-s3"; | ||
import { Upload } from "@aws-sdk/lib-storage"; | ||
|
||
import { configuration } from "./config"; | ||
|
||
const idPool = "us-west-2:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; | ||
const Bucket = configuration.Bucket; | ||
const region = "us-west-2"; | ||
|
||
const sleep = async (seconds: number) => { | ||
return new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
}; | ||
|
||
const fakeStreamOfUnknownlength = new ReadableStream({ | ||
start: async (controller) => { | ||
for (let index = 0; index < 8; index++) { | ||
const time = Math.random() * 5; | ||
await sleep(time); | ||
console.log(`Delaying part ${index} for ${time}`); | ||
controller.enqueue(`[part ${index}] with ${"#".repeat(2000000)}`); | ||
} | ||
controller.close(); | ||
}, | ||
}); | ||
|
||
const uploadIndeterminateLengthStreamBrowser = async () => { | ||
const client = new S3Client({ | ||
region, | ||
credentials: fromCognitoIdentityPool({ | ||
client: new CognitoIdentityClient({ region }), | ||
identityPoolId: idPool, | ||
}), | ||
}); | ||
|
||
const Key = configuration.Key; | ||
|
||
let upload = new Upload({ | ||
client, | ||
params: { | ||
Key, | ||
Bucket, | ||
Body: fakeStreamOfUnknownlength, | ||
}, | ||
}); | ||
|
||
upload.on("httpUploadProgress", (progress: ProgressEvent) => { | ||
console.log(progress); | ||
}); | ||
|
||
const uploadResult = await upload.done(); | ||
console.log("done uploading", uploadResult); | ||
}; | ||
|
||
uploadIndeterminateLengthStreamBrowser(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { S3Client } from "@aws-sdk/client-s3"; | ||
import { Upload } from "@aws-sdk/lib-storage"; | ||
|
||
import { Readable } from "stream"; | ||
import { configuration } from "./config"; | ||
|
||
const Bucket = configuration.Bucket; | ||
const region = "us-west-2"; | ||
|
||
const sleep = async (seconds: number) => { | ||
return new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
}; | ||
|
||
async function* generateContents() { | ||
for (let index = 0; index < 8; index++) { | ||
const time = Math.random() * 10; | ||
await sleep(time); | ||
console.log(`Delaying part ${index} for ${time}`); | ||
yield `[Part ${index}] ${"#".repeat(2000000)}`; | ||
} | ||
} | ||
const fakeStreamOfUnknownlength = Readable.from(generateContents()); | ||
|
||
const uploadIndeterminateLengthStreamNode = async () => { | ||
const Key = configuration.Key; | ||
let upload = new Upload({ | ||
client: new S3Client({ region }), | ||
params: { | ||
Key, | ||
Bucket, | ||
Body: fakeStreamOfUnknownlength, | ||
}, | ||
}); | ||
|
||
upload.on("httpUploadProgress", (progress: ProgressEvent) => { | ||
console.log(progress); | ||
}); | ||
|
||
const uploadResult = await upload.done(); | ||
console.log("done uploading", uploadResult); | ||
}; | ||
|
||
uploadIndeterminateLengthStreamNode(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.