Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Allow maxChunkSize to be a function for dynamic chunk size support #3486

Merged
merged 1 commit into from
Aug 27, 2017

Conversation

cubiclesoft
Copy link
Contributor

This change allows maxChunkSize to be a function that returns a dynamic result instead of using a fixed value.

This can be useful for allowing an application to use the last known bit rate to decide what the next chunk size should be in order to cap the client-side upload speed over time.

@blueimp blueimp merged commit 6589b45 into blueimp:master Aug 27, 2017
@blueimp
Copy link
Owner

blueimp commented Aug 27, 2017

Thanks @cubiclesoft !

@pbtdamyanpetkov
Copy link

Hi to all,
I am using jQuery File Upload and I am happy of it. Unfortunately I faced problem with network speed - some times network speed is slow and requests are stopped because ot timeout is reached. I want to use this new feature of dynamic change of maxChunkSize to send smaller packages in the time when network is slow.
Is it possible to describe how to use the new feature with some code example?

Thanks in advanced

@cubiclesoft
Copy link
Contributor Author

I used the feature over here: https://github.com/cubiclesoft/php-cool-file-transfer

Relevant source code:

https://github.com/cubiclesoft/php-cool-file-transfer/blob/master/support/cft.js

Basically, the following is an example use-case:

youroptions = {
	...
	maxChunkSize: function(options) {
		if (options._progress.loaded === 0)  return 65536;

		var size = Math.floor(options._progress.bitrate * 1.25 / 8);

		if (size < 65536)  size = 65536;

		// Replace 1048576 with whatever the maximum allowed transfer amount is (i.e. what you currently pass to maxChunkSize).
		return Math.min(1048576, size);
	}
};

@pbtdamyanpetkov
Copy link

Thank you very much for the solution!
It works just perfect!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants