+
+[Drash](https://drash.land/drash/) is a framework for Deno's HTTP server. In a
+`POST` request handler, the body parser can pull file data into a `Uint8Array`:
+
+{`\
+// @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts"
+import * as XLSX from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs';
+/* load the codepage support library for extended support with older formats */
+import * as cptable from 'https://cdn.sheetjs.com/xlsx-${current}/package/dist/cpexcel.full.mjs';
+XLSX.set_cptable(cptable);
+
+import * as Drash from "https://deno.land/x/drash@v2.5.4/mod.ts";
+
+class SheetResource extends Drash.Resource {
+ public paths = ["/"];
+
+ public POST(request: Drash.Request, response: Drash.Response) {
+ // highlight-next-line
+ const file = request.bodyParam("file");
+ if (!file) throw new Error("File is required!");
+ // highlight-next-line
+ var wb = XLSX.read(file.content, {type: "buffer"});
+ var html = XLSX.utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]);
+ return response.html(html);
+ }
+}
+
+const server = new Drash.Server({ hostname: "", port: 7262, protocol: "http",
+ resources: [
+ // highlight-next-line
+ SheetResource,
+ ],
+});
+
+server.run();`}
+
+:::note
+
+Deno must be run with the `--allow-net` flag to enable network requests:
+
+```bash
+$ deno run --allow-net test-server.ts
+```
+
+To test, submit a POST request to http://localhost:7262 including a file:
+
+```bash
+curl -X POST -F "file=@test.xlsx" http://localhost:7262/
+```
+
+:::
+
+
+
+
+
### Example: Remote File
@@ -355,6 +460,7 @@ Node 17.5 and 18.0 have native support for fetch:
```js
const XLSX = require("xlsx");
+const url = "http://oss.sheetjs.com/test_files/formula_stress_test.xlsx";
const data = await (await fetch(url)).arrayBuffer();
/* data is an ArrayBuffer */
const workbook = XLSX.read(data);
@@ -368,6 +474,7 @@ For broader compatibility, third-party modules are recommended.
var XLSX = require("xlsx");
var request = require("request");
+var url = "http://oss.sheetjs.com/test_files/formula_stress_test.xlsx";
request({url: url, encoding: null}, function(err, resp, body) {
var workbook = XLSX.read(body);
@@ -381,6 +488,7 @@ request({url: url, encoding: null}, function(err, resp, body) {
const XLSX = require("xlsx");
const axios = require("axios");
+const url = "http://oss.sheetjs.com/test_files/formula_stress_test.xlsx";
(async() => {
const res = await axios.get(url, {responseType: "arraybuffer"});
/* res.data is a Buffer */
@@ -390,6 +498,34 @@ const axios = require("axios");
})();
```
+
+