3.1 KiB
title | pagination_prev | pagination_next |
---|---|---|
Deno Deploy | demos/local/index | demos/extensions/index |
import current from '/version.js'; import CodeBlock from '@theme/CodeBlock';
Deno Deploy offers "Serverless Functions" powered by Deno.
The Deno installation instructions apply to Deno Deploy scripts.
:::warning
Deno Deploy does not offer any sort of temporary file access in functions.
This breaks web frameworks that use the filesystem in body parsing.
:::
:::caution
When the demo was last tested, Deno Deploy required a GitHub account.
:::
Supported Frameworks
When the demo was last tested, the drash
server framework used an in-memory
approach for parsing POST request bodies.
Parsing Data
When files are submitted via HTTP POST, the bodyParam
method can fetch data.
The content
property of the returned object can be parsed with XLSX.read
.
The following example assumes the file is submitted at field name file
:
{\ // @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts" import { read, utils } from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs'; import * as Drash from "https://cdn.jsdelivr.net/gh/drashland/drash@v2.8.0/mod.ts"; \n\ class SheetJSResource extends Drash.Resource { public paths = ["/"]; \n\ public POST(request: Drash.Request, response: Drash.Response) { // highlight-start /* get data from body */ const file = request.bodyParam<Drash.Types.BodyFile>("file"); /* parse */ var wb = read(file.content, {type: "buffer", dense: true}); // highlight-end /* generate HTML from first worksheet */ return response.html(utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]])); } }
}
Demo
:::note
This demo was last tested on 2023 June 05. The service https://s2c.sheetjs.com was implemented using this exact sequence.
:::
-
Register and Sign in.
-
Click "New Project" to create a new Project. In the next screen, look for the "Hello World" sample and click the corresponding "Fork" button.
-
Download
s2c.ts
. Open with a text editor and copy the contents into the playground editor (left pane). -
Click "Save and Deploy".
Testing
-
Download the test file https://sheetjs.com/pres.xlsx
-
In the browser window, click "Choose File" and select the downloaded file. Click "Submit" and the page will show the contents in a HTML TABLE.
-
Click the "Fullscreen" icon in the top-right corner of the page window.
-
Open a terminal window and download https://sheetjs.com/pres.numbers:
curl -LO https://sheetjs.com/pres.numbers
- Copy the first
curl
line from the page and run in the terminal. For example, if the deployment isclean-badger-69
, the command would be
curl -X POST -F"file=@pres.numbers" https://clean-badger-69.deno.dev/
The output will be an HTML table
- Copy the second
curl
line from the page and run in the terminal. For example, if the deployment isclean-badger-69
, the command would be
curl -X POST -F"file=@pres.numbers" -F"type=csv" https://clean-badger-69.deno.dev/
The output will be CSV.