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

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion models/AmazonS3.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

// if these is an asyncManager then check the file size
// outside of coldbox there is no asyncManager so this would fall apart
byteCount = getFileInfo( arguments.filepath ).size;
}

if ( byteCount <= variables.multiPartByteThreshold ) {
arguments.data = fileReadBinary( arguments.filepath );
Expand Down
Loading