Skip to content

Commit

Permalink
Enable non-streaming upload in @aws-lite/s3 PutObject
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Sep 28, 2023
1 parent 2cb10db commit 2ac274c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions plugins/s3/src/put-object.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ const PutObject = {
throw err
}

// TODO non-streaming upload
if (dataSize > minChunkSize) {
if (dataSize <= minChunkSize) {
let payload = await readFile(file)
return {
path: `/${Bucket}/${Key}`,
method: 'PUT',
headers,
payload,
}
}
else {
// We'll assemble file indices of chunks here
let chunks = [
// Reminder: no payload is sent with the canonical request
Expand Down Expand Up @@ -80,8 +88,7 @@ const PutObject = {
chunk.end = end
}

totalRequestSize += payloadMetadata(chunkSize, dummySig).length +
chunkBreak.length
totalRequestSize += payloadMetadata(chunkSize, dummySig).length + chunkBreak.length
chunks.push({ ...chunk, chunkSize })
}

Expand Down
6 changes: 4 additions & 2 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function request (params, creds, region, config, metadata) {
// Body - JSON-ify payload where convenient!
let body = params.payload || params.body || params.data || params.json
// Lots of potentially weird valid json (like just a null), deal with it if / when we need to I guess
if (typeof body === 'object') {
if (typeof body === 'object' && !(body instanceof Buffer)) {
// Backfill content-type if it's just an object
if (!contentType) contentType = 'application/json'

Expand Down Expand Up @@ -103,7 +103,9 @@ module.exports = function request (params, creds, region, config, metadata) {
/* istanbul ignore next */
if (config.debug) {
let { method = 'GET', service, host, path, port = '', headers, protocol, body } = options
let truncatedBody = body?.length > 1000 ? body?.substring(0, 1000) + '...' : body
let truncatedBody
if (body instanceof Buffer) truncatedBody = `<body buffer of ${body.length}b>`
else truncatedBody = body?.length > 1000 ? body?.substring(0, 1000) + '...' : body
console.error('[aws-lite] Requesting:', {
service,
method,
Expand Down

0 comments on commit 2ac274c

Please sign in to comment.