-
Notifications
You must be signed in to change notification settings - Fork 751
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
Stream support for FileUpload #471
Changes from 1 commit
a58cb35
5dc9afd
d99d077
54a79a6
27c0121
87328dd
f109d07
8764b7d
183d644
05a84c4
5acf777
c039eeb
aa90cec
a1ebecc
d963055
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,6 +203,17 @@ var utils = module.exports = { | |
|
||
return obj; | ||
}, | ||
|
||
/** | ||
* Determine if file data is a derivative of EventEmitter class. | ||
* https://nodejs.org/api/events.html#events_events | ||
*/ | ||
checkForStream: function (obj) { | ||
if (obj.file && obj.file.data) { | ||
return typeof obj.file.data.on === 'function' && typeof obj.file.data.emit === 'function'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not do an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rattrayalex-stripe good question! An There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, thanks! That reasoning makes sense. A duck-type check as you have here may make more sense; let's see how it looks after the refactor. Cheers |
||
} | ||
return false; | ||
}, | ||
}; | ||
|
||
function emitWarning(warning) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,5 +78,42 @@ describe('File Uploads Resource', function() { | |
expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); | ||
}); | ||
|
||
it('Streams a file and sends the correct file upload request', function() { | ||
var testFilename = path.join(__dirname, 'data/minimal.pdf'); | ||
var f = fs.createReadStream(testFilename); | ||
|
||
stripe.fileUploads.create({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, my fault! nice catch @jlomas-stripe - I just ran it through the debugger with an intentional fail and noticed exactly what you were talking about. I'll update this asap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries. This is a super-insidious mocha thing. Not including a |
||
purpose: 'dispute_evidence', | ||
file: { | ||
data: f, | ||
name: 'minimal.pdf', | ||
type: 'application/octet-stream', | ||
}, | ||
}) | ||
.then(function() { | ||
expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); | ||
}); | ||
}); | ||
|
||
it('Streams a file and sends the correct file upload request [with specified auth]', function() { | ||
var testFilename = path.join(__dirname, 'data/minimal.pdf'); | ||
var f = fs.createReadStream(testFilename); | ||
|
||
stripe.fileUploads.create({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: you need to |
||
purpose: 'dispute_evidence', | ||
file: { | ||
data: f, | ||
name: 'minimal.pdf', | ||
type: 'application/octet-stream', | ||
}, | ||
}, TEST_AUTH_KEY) | ||
.then(function() { | ||
expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); | ||
expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is fine, but would you mind adding
var Buffer = require('safe-buffer').Buffer;
at the top of the file? That way if we add more code that usesBuffer
in this file it will use the safe version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ob-stripe thanks for the quick response and catching my oversight on
safe-buffer
! I noticedsafe-buffer
in the MultipartDataGenerator.js file, but totally forgot about requiring it here. I'll update the code asap and keep a look out for any other feedback from @jlomas-stripe @rattrayalex-stripe .