Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@uppy/transloadit: fix unhandledPromiseRejection failures (#3197)
* @uppy/transloadit: fix unhandledPromiseRejection failures Fixes: #3189 * Add transloadit2 to end2end test matrix
- Loading branch information
Showing
7 changed files
with
190 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Uppy test page</title> | ||
</head> | ||
<body> | ||
<style> | ||
main { | ||
max-width: 700px; | ||
margin: auto; | ||
} | ||
</style> | ||
<main> | ||
<h2>Uppy Transloadit</h2> | ||
<div id="uppy-transloadit"></div> | ||
</main> | ||
|
||
<link href="uppy.min.css" rel="stylesheet"> | ||
<script src="bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const Uppy = require('@uppy/core') | ||
const Dashboard = require('@uppy/dashboard') | ||
const Transloadit = require('@uppy/transloadit') | ||
|
||
function initUppyTransloadit (transloaditKey) { | ||
const uppyTransloadit = new Uppy({ | ||
id: 'uppyTransloadit', | ||
debug: true, | ||
autoProceed: true, | ||
}) | ||
|
||
uppyTransloadit | ||
.use(Dashboard, { | ||
target: '#uppy-transloadit', | ||
inline: true, | ||
}) | ||
.use(Transloadit, { | ||
service: 'https://api2-ap-southeast-1.transloadit.com', | ||
params: { | ||
steps: { | ||
crop_thumbed: { | ||
use: [':original'], | ||
robot: '/image/resize', | ||
height: 100, | ||
resize_strategy: 'crop', | ||
width: 100, | ||
}, | ||
}, | ||
}, | ||
getAssemblyOptions () { | ||
return { | ||
params: { | ||
auth: { key: transloaditKey }, | ||
template_id: 'uppyTransloadit', | ||
}, | ||
} | ||
}, | ||
waitForEncoding: true, | ||
}) | ||
|
||
uppyTransloadit.on('transloadit:result', (stepName, result) => { | ||
// 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 | ||
}) | ||
} | ||
|
||
window.initUppyTransloadit = initUppyTransloadit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* global browser, expect, capabilities, $ */ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { selectFakeFile, supportsChooseFile, ensureInputVisible } = require('../utils') | ||
|
||
const testURL = 'http://localhost:4567/transloadit' | ||
|
||
function setTransloaditKeyAndInit (transloaditKey) { | ||
window.initUppyTransloadit(transloaditKey) | ||
} | ||
|
||
describe('Transloadit file processing', () => { | ||
beforeEach(async () => { | ||
await browser.url(testURL) | ||
}) | ||
|
||
it('should upload a file to Transloadit and crop it', async function test () { | ||
const transloaditKey = process.env.TRANSLOADIT_KEY | ||
if (transloaditKey === undefined) { | ||
console.log('skipping Transloadit integration test') | ||
return this.skip() | ||
} | ||
|
||
const wrapper = await $('#uppy-transloadit') | ||
await wrapper.waitForExist() | ||
|
||
await browser.execute(setTransloaditKeyAndInit, transloaditKey) | ||
|
||
const input = await $('#uppy-transloadit .uppy-Dashboard-input') | ||
const result = await $('#uppy-result') | ||
|
||
await input.waitForExist() | ||
await browser.execute(ensureInputVisible, '#uppy-transloadit .uppy-Dashboard-input') | ||
|
||
if (supportsChooseFile(capabilities)) { | ||
await input.setValue(path.join(__dirname, '../../resources/image.jpg')) | ||
} else { | ||
const img = path.join(__dirname, '../../resources/image.jpg') | ||
await browser.execute( | ||
selectFakeFile, | ||
'uppyTransloadit', | ||
path.basename(img), // name | ||
'image/jpeg', // type | ||
fs.readFileSync(img, 'base64') // b64 | ||
) | ||
// browser.execute(selectFakeFile, 'uppyTransloadit') | ||
} | ||
await result.waitForExist(25000) | ||
const text = await result.getText() | ||
expect(text).to.be.equal('ok') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters