Skip to content
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

Fix vanilla no async manager #44

Conversation

jordanclark
Copy link
Contributor

Remove dependency on async manager which doesn't outside of coldbox, without this a large upload would fail when this.asyncManager is undefined.

async doesn't exist outside of coldbox so this ensures it won't try to split uploads and then fail when asyncManager is undefined.
@@ -800,7 +800,12 @@ component accessors="true" singleton {
arguments.contentType = getFileMimeType( arguments.filepath );
}

var byteCount = getFileInfo( arguments.filepath ).size;
var byteCount = 0;
if( structKeyExists( variables, "asyncManager" ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's allow multi-part uploads when AsyncManager is null ( e.g. outside Coldbox/CommandBox context ). So, in the try/catch block for the multipart, we can do:

var processPart = function( part ){
	var channel = part.channel.position( part.offset );
	var buffer  = createObject( "java", "java.nio.ByteBuffer" ).allocate( part.limit );
	channel.read( buffer );

	return {
		"partNumber" : part.partNumber,
		"size"       : part.limit,
		"channel"    : part.channel,
		"response"   : s3Request(
			method     = "PUT",
			resource   = bucketName & "/" & uri,
			body       = buffer.array(),
			timeout    = part.timeout,
			parameters = {
				"uploadId"   : part.uploadId,
				"partNumber" : part.partNumber
			},
			headers = { "content-type" : "binary/octet-stream" }
		)
	};
};

if( !isNull( variables.asyncManagers ) ){
	variables.asyncManager.allApply( parts, processPart );
} else {
	parts = parts.map( processPart );
}

jclausen added a commit that referenced this pull request Feb 25, 2025
@jclausen
Copy link
Contributor

Since there is now an AsyncManager in CommandBox this should work in any context. I have added this manually, using my recommendations in the PR in commit 76a0a35

@jclausen jclausen closed this Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants