Published
Edited
Mar 11, 2020
1 fork
Insert cell
md`# Upload ZIP file to API via jsZIP & Request`
Insert cell
jszip = require('https://bundle.run/jszip@3.2.2')
Insert cell
request = require('https://bundle.run/request@2.88.2')
Insert cell
ngrok_url = "https://5cace103.ngrok.io"
Insert cell
zip = new jszip();
Insert cell
//zip.folder("netlify_site").file("index.html", html_string, {base64: true});
Insert cell
// zip.file("netlify_site/index.html", "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>.iframe-container{overflow:hidden}.iframe-container iframe{border:0;height:100%;left:0;position:absolute;top:0;width:100%}</style><div class=\"iframe-container\"> <iframe src=\"" + "https://example.com/version-test" + "\"></iframe></div>");
Insert cell
zip.file("hello.txt", "hello world");
Insert cell
zip.generateAsync({type:"base64"}).then(function (zippedContent) {
// DOWNLOAD ZIP FILE IN BROWSER
//location.href="data:application/zip;base64," + content;
console.log(zippedContent.length)
// UPLOAD ZIP FILE TO API ENDPOINT
var sentRequest = request({
method: "POST",
uri: ngrok_url,
form: {zip_blob: zippedContent},
headers: {'Content-Type': 'application/octet-stream'}
});
});
Insert cell
//thing = await zip.generateAsync({type: "base64"})
Insert cell
//location.href="data:application/zip;base64," + thing;
Insert cell
// zip
// .generateInternalStream({type:"base64"})
// .on('data', function (data, metadata) {
// // data is a Uint8Array because that's the type asked in generateInternalStream
// // metadata contains for example currentFile and percent, see the generateInternalStream doc.
// location.href="data:application/zip;base64," + data;
// })
// .on('error', function (e) {
// // e is the error
// })
// .on('end', function () {
// // no parameter
// })
// .resume();

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more