Created
July 23, 2022 02:47
-
-
Save S-codes14/ab3542a3f2337447faa3e8197e871586 to your computer and use it in GitHub Desktop.
Coda template for a pack
This file contains hidden or 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
import * as coda from "@codahq/packs-sdk"; | |
export const pack = coda.newPack(); | |
pack.addNetworkDomain("codahosted.io"); | |
pack.addFormula({ | |
name: "FileSize", | |
description: "Gets the file size of a file attachment, in bytes.", | |
parameters: [ | |
coda.makeParameter({ | |
type: coda.ParameterType.File, | |
name: "file", | |
description: | |
"The file to operate on.", | |
}), | |
], | |
resultType: coda.ValueType.Number, | |
execute: async function ([fileUrl], context) { | |
// Fetch the file content. | |
let response = await context.fetcher.fetch({ | |
method: "GET", | |
url: fileUrl, | |
isBinaryResponse: true, // Required when fetching binary content. | |
}); | |
// The binary content of the response is returned as a Node.js Buffer. | |
// See: https://nodejs.org/api/buffer.html | |
let buffer = response.body as Buffer; | |
// Return the length, in bytes. | |
return buffer.length; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment