Skip to content

Commit

Permalink
Add requireUploadMetaData option.
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-kos committed Jan 18, 2017
1 parent cc97f50 commit 5d695a1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -161,7 +161,20 @@ The plugin supports several parameters.
<code>wait</code>
</td>
<td markdown="1">
Specifies whether the plugin should wait for files to be processed before submitting the form. This is <code>false</code> by default.
Specifies whether the plugin should wait for files to be transcoded before submitting the form. This is <code>false</code> by default.
</td>
</tr>
<tr>
<td markdown="1">
<code>requireUploadMetaData</code>
</td>
<td markdown="1">
Specifies whether the plugin should wait for meta data of uploaded files to first be extracted before it calls the <code>onSuccess</code> callback.
If you set <code>wait</code> to <code>true</code>, this option does not have any effect, because extracting meta of uploaded files is a prerequisite for the files to be transcoded.

However, if you set <code>wait</code> to <code>false</code>, the <code>onSuccess</code> callback is fired as soon as the uploading is finished. The <code>uploads</code> array in the passed assembly object will be empty in this case. If you need this uploads array to be populated, set this option to <code>true</code>.

This is <code>false</code> by default, to fire the <code>onSuccess</code> callback as soon as possible to increase perceived performance.
</td>
</tr>
<tr>
Expand Down
6 changes: 4 additions & 2 deletions index.html
Expand Up @@ -11,7 +11,8 @@
</form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://localjquerysdk.com/build/jquery.transloadit2-latest.js"></script>
<!-- <script src="http://localjquerysdk.com/build/jquery.transloadit2-latest.js"></script> -->
<script src="https://assets.transloadit.com/js/jquery.transloadit2-v2.8.0.js"></script>

<script type="text/javascript">
window.YOUR_TRANSLOADIT_AUTH_KEY='YOUR_AUTH_KEY'
Expand All @@ -21,9 +22,10 @@
<script type="text/javascript">
$(function() {
$('#upload-form').transloadit({
wait: true,
wait: false,
autoSubmit: false,
assets: 'http://localjquerysdk.com/build/',
requireUploadMetaData: true,
triggerUploadOnFileSelection: true,
fields: '*',
resumable: true,
Expand Down
24 changes: 19 additions & 5 deletions js/lib/jquery.transloadit2.js
Expand Up @@ -29,6 +29,7 @@
wait : false,
processZeroFiles : true,
triggerUploadOnFileSelection : false,
requireUploadMetaData : false,
autoSubmit : true,
modal : true,
exclude : '',
Expand Down Expand Up @@ -594,10 +595,11 @@
}

self.pollRetries = 0;
var isUploading = assembly.ok === 'ASSEMBLY_UPLOADING';
var isExecuting = assembly.ok === 'ASSEMBLY_EXECUTING';
var isCanceled = assembly.ok === 'ASSEMBLY_CANCELED';
var isComplete = assembly.ok === 'ASSEMBLY_COMPLETED';
var isUploading = assembly.ok === 'ASSEMBLY_UPLOADING';
var isExecuting = assembly.ok === 'ASSEMBLY_EXECUTING';
var isCanceled = assembly.ok === 'ASSEMBLY_CANCELED';
var isComplete = assembly.ok === 'ASSEMBLY_COMPLETED';
var uploadMetaDataExtracted = assembly.upload_meta_data_extracted;

if (assembly.bytes_expected > 0) {
self._options.onProgress(assembly.bytes_received, assembly.bytes_expected, assembly);
Expand Down Expand Up @@ -635,7 +637,19 @@
return;
}

var isEnded = isComplete || (!self._options['wait'] && isExecuting);
var isEnded = false

if (isComplete) {
isEnded = true
}

if (isExecuting && !self._options['wait']) {
isEnded = true

if (self._options['requireUploadMetaData'] && !uploadMetaDataExtracted) {
isEnded = false
}
}

if (assembly.bytes_expected > 0) {
self.renderProgress(assembly, isEnded, self._options['wait']);
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "transloadit-jquery",
"description": "Integrate Transloadit's uploading and encoding capabilites into browsers using jQuery",
"version": "2.7.3",
"version": "2.8.0",
"scripts": {
"build": "npm run clean && npm run css && npm run browserify && npm run uglify && npm run gzip && npm run versionify",
"clean": "rm -rf build/*",
Expand Down

0 comments on commit 5d695a1

Please sign in to comment.