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

@uppy/transloadit: pass fields to transloadit #3228

Merged
merged 2 commits into from Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 7 additions & 14 deletions packages/@uppy/transloadit/src/AssemblyOptions.js
Expand Up @@ -24,19 +24,6 @@ function validateParams (params) {
}
}

/**
* Normalize Uppy-specific Assembly option features to a Transloadit-
* compatible object.
*/
function normalizeAssemblyOptions (file, assemblyOptions) {
// eslint-disable-next-line no-param-reassign
assemblyOptions.fields = Array.isArray(assemblyOptions.fields)
? Object.fromEntries(assemblyOptions.fields.map((fieldName) => [fieldName, file.meta[fieldName]]))
: {}

return assemblyOptions
}

/**
* Combine Assemblies with the same options into a single Assembly for all the
* relevant files.
Expand Down Expand Up @@ -78,9 +65,15 @@ class AssemblyOptions {
const options = this.opts

const assemblyOptions = await options.getAssemblyOptions(file, options)
if (Array.isArray(assemblyOptions.fields)) {
assemblyOptions.fields = Object.fromEntries(
assemblyOptions.fields.map((fieldName) => [fieldName, file.meta[fieldName]])
)
} else if (assemblyOptions.fields == null) {
assemblyOptions.fields = {}
}

validateParams(assemblyOptions.params)
normalizeAssemblyOptions(file, assemblyOptions)

return {
fileIDs: [file.id],
Expand Down
20 changes: 8 additions & 12 deletions test/endtoend/transloadit2/main.js
Expand Up @@ -33,24 +33,20 @@ function initUppyTransloadit (transloaditKey) {
auth: { key: transloaditKey },
template_id: 'uppyTransloadit',
},
fields: {
message: 'test',
},
}
},
waitForEncoding: true,
})

uppyTransloadit.on('transloadit:result', (stepName, result) => {
uppyTransloadit.on('transloadit:result', (_, __, assembly) => {
// use transloadit encoding result here.
console.log('Result here ====>', stepName, result)
console.log('Cropped image url is here ====>', result.url)

const img = new Image()
img.onload = function onload () {
const result = document.createElement('div')
result.setAttribute('id', 'uppy-result')
result.textContent = 'ok'
document.body.appendChild(result)
}
img.src = result.url
const result = document.createElement('div')
result.setAttribute('id', 'uppy-result')
result.textContent = assembly.fields.message === 'test' ? 'ok' : 'fail'
document.body.appendChild(result)
})
}

Expand Down