I am having trouble calling the stripe.files.create() function to upload an identity document for a stripe connect account.

I've tried all the examples on stripe's documentation and followed this guide: https://stripe.com/docs/file-upload however i still am still receiving errors.

This is the cloud function which takes in the url of the image stored on Firebase Storage (rp is the request-promise modules from https://www.npmjs.com/package/request-promise):

exports.testFileUpload = functions.https.onCall((data, context) => {
    return rp(data.dlUrl).then(response => {
        var imgFile = response
        console.log(imgFile)
            return stripe.files.create({
                purpose: 'identity_document',
                file: {
                    data: imgFile,
                    name: 'file.jpeg',
                    type: 'image/jpeg'
                }
            }).then((file) => {
                console.log(file)
                return file
            }).catch((err) => {
                console.log(err)
                return err
            })
    })

The expected output should be a file object from stripe, however i'm getting this error message: "We don't currently support that file type. Try uploading a file with one of the following mimetypes: application/pdf, image/jpeg, image/png"

Any help would be greatly appreciated! Thanks!

UPDATE

I've tried to pipe the download link into a file, and referenced the file in the stripe.files.create() request but I am still getting the same unsupported filetype error above

exports.testFileUpload = functions.https.onCall((data, context) => {
    request(data.dlUrl).pipe(fs.createWriteStream('/tmp/IC.jpg'))
    var fp = fs.readFileSync('/tmp/IC.jpg');
    return stripe.files.create({
        purpose: 'identity_document',
        file: {
            data: fp,
            name: 'IC.jpg',
            type: 'application/octet-stream'
        }
    }).then((file) => {
        console.log(file)
        return file
    }).catch((err) => {
        console.log(err)
        return err
    })
})

0 Answers