Upload a Document without Access to a File System

Our setup uses a server-less configuration in the sense that we do not have access to any file system; all we can go is GET a file from a URL (such as in an arrayBuffer). I’ve tried without success to be able to POST the contents to Dwolla’s documents endpoint. We’ve tried:

  • uploading a base64 string
  • uploading as an arrayBuffer
  • getting the file as a base64 string and converting to (and uploading as) a blob
  • getting the file as an arrayBuffer and converting to (and uploading as) a blob

Wondering if anyone has a code snippet I could look at if anyone has faced a similar scenario of needing to first GET a file from an off-site URL and then upload that to Dwolla directly (i.e., without saving it to a file system first). Thanks for your help! Happy to buy you a coffee!

Hey @barrownicholas , what language are you using (Node.js, python, other?) and are you open to using a third party dependency?

Hey @spencer :
Thanks for getting back to me, I just now think I’ve got a working solution! Going to post it here to save someone else the trouble.

properties = {
    isntLiveVersion: true,
    customer: "0d596...0467b",
    fileURL: "https://nicholasrbarrow.com/.../test-document-upload-success.png",
    filename: "test-document-upload-success.png",
    documentType: "license",
    bearerToken: "Bearer ..."

async function run_server(properties, context) {

    const axios = require("axios");
    const FormData = require("form-data");

    const baseURL = properties.isntLiveVersion ? "https://api-sandbox.dwolla.com" : "https://api.dwolla.com";

    const response = await axios.get(properties.fileURL, { responseType: 'stream' });
    const form = new FormData();
    // Pass image stream from response directly to form
    form.append('file', response.data, properties.filename);
    form.append('documentType', properties.documentType);

    const headers = {
        'Content-Type': 'multipart/form-data',
        'Authorization': properties.bearerToken,
        'Accept': "application/vnd.dwolla.v1.hal+json"
    const resp = await axios.post(`${baseURL}/customers/${properties.customer}/documents`, form, {headers: headers});
    // console.log(resp)

} run_server(properties,null);