Is there any way to store/upload a sparkline svg?

This topic was automatically generated from Slack. You can find the original thread here.

Shai Perednik : any way to store/upload a sparkline svg? I have node.js code I found to create the sparkline, but not sure how pipedream handles local files so I can then upload it somewhere

Dylan Sather (Pipedream) : Take a look at https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/ and let me know if that helps

Shai Perednik : will do ty!!! still playing around w/ the node.js code locally to create the sparkline locally. will try that out shortly.

Shai Perednik : getting close but getting an error: https://pipedream.com/@shaiss/sparkline-test-p_NMCD59w

Shai Perednik : ```
ACTIVE_HANDLEThis step was still trying to run code when the step ended. Make sure you promisify callback functions and await all Promises. (Reason: FSReqCallback, Learn more: Running asynchronous code)

Shai Perednik : ```
const sparkline = require(‘node-sparkline’);
const fs = require(‘fs’);
const path = require(‘path’);
const { promisify } = require(‘util’);
const writeFile = promisify(fs.writeFile);
const values = [
7.45162149487362,
7.465136012334006,
7.461519350494333,
7.465413133687816,
7.511812989297731,
7.8776700262848705,
8.032346630203442,
8.16774825735731,
8.229668975583916,
8.238856463169155,
8.257030953739477,
8.236774822602545,
8.190300721027079,
8.13603900682545,
7.93046805606676,
7.873374158326343,
7.744961642971777,
7.81594453373647,
7.8637008039663385,
7.8509859843825485,
7.774829877417928,
7.7928900555733325,
7.802988598458197,
7.811829326761041,
7.809513333293174,
7.755694552580595,
7.740737298560772,
7.74028834115583,
7.736695879281692,
7.8722879337259215,
7.983071455545634,
8.058338236458502,
8.083090572680065,
8.245677151169778,
8.422209847286164,
8.360618922692863,
8.377466223406124,
8.410567947020702,
8.203756986058428,
8.138869751165217,
8.150320536729287,
8.255427190765817,
8.234015221444672,
8.32323859535365,
8.399964490840985,
8.369376812486951,
8.396646528694426,
8.476018970266116,
8.601040094779913,
8.653684187748134,
8.669531929002035,
8.75787394946614,
8.610224379717435,
8.826478684824501,
9.254604630288334,
9.4425084451639,
9.655424003726568,
9.514980168649606,
9.50452321495158,
9.34102252811664,
9.504210992279024,
9.584058247196362,
9.62409466404434,
9.58620251496069,
9.556253532418923,
9.551316876883936,
9.629350226102432,
9.630441160758757,
9.423599458967375,
9.631422356177499,
9.564332486800726,
9.692641605412843,
9.620514058161152,
9.711097505491407,
9.790968990509276,
9.795394005541661,
9.805505507268508,
9.755163114125788,
9.786393756280214,
9.65383194888734,
9.371223163817163,
9.333064636470029,
9.392793265218367,
9.42918366346151,
9.378188776334413,
9.161911971095552,
8.908976735168041,
8.998591205295943,
8.86119804919629,
8.705310429352274,
8.672491467964697,
8.66018442224833,
8.697003863890908,
8.658116987717094,
8.81197229728009,
9.080238887017112,
8.996947622581692,
8.828905538101615,
8.854916765407182,
8.617945648751684,
8.63866319409813,
8.643344601216542,
8.521692192951871,
8.539957442721386,
8.515027737186955,
8.587694622710071,
8.65752808321314,
8.609443552098547,
8.57258413338731,
8.5544728042285,
8.590224962764903,
8.614407107056692,
8.593195877435297,
8.525904837005037,
8.43499770655282,
8.484828598550685,
8.657854167302537,
8.764298684103162,
9.257060172600116,
9.23601646121829,
9.344144079057996,
9.164669885696714,
9.10033926934154,
9.110017066872873,
9.070139694356872,
9.156952150982484,
9.984874475898685,
9.570086144819529,
9.693334058951839,
9.38151954184341,
9.514025707420691,
9.507324295116355,
9.608760727642208,
9.517461749024964,
9.514193077146198,
9.863268401452943,
9.912986379354715,
9.998331791015696,
10.094629517602177,
10.245244210395791,
10.240302967862881,
10.223367528548648,
10.261645687066025,
11.800825676399295,
12.052693548659365,
11.904241306948931,
11.822314657602474,
12.230277585232571,
13.512054848486294,
12.675104774147874,
12.705815289569507,
12.564530849193703,
12.61735682536595,
12.518586670949885,
12.689352790506367,
13.11039983067567,
13.407938392152904,
13.949617785120928,
13.467738708696,
13.899645824427985,
15.637331996606186,
15.337937695286223,
14.816581598662703,
14.48289778320874,
14.5241804340251,
13.97155114023251,
13.671995384944877,
13.82464643312032,
];

try {
const svg = sparkline({
values,
width: 150,
height: 50,
stroke: ‘#57bd0f’,
strokeWidth: 2,
strokeOpacity: 1,
});

//fs.writeFileSync(/tmp/myfile, Buffer.from(sparkline));
writeFile(path.join(__dirname, ‘sparkline.svg’), svg);
// svg is a string with SVG + polyline tags
// …
} catch (e) {
console.error(e.toString());
}

Dylan Sather (Pipedream) : I think it might be a false positive. Can you try reading the file in the next step and see if it has the right content?

Shai Perednik : ~got it working~

Shai Perednik : oops no strikethrough

Shai Perednik : it’s working now

Shai Perednik : I’ll be done in a bit, the next step is uploading, I think that’s easy

Shai Perednik : would be cool if you guys inc this in your demo repo “creating a sparkline graph w/ pipedream”

Dylan Sather (Pipedream) : if you’re open to it, we accept PRs on our repo. If you develop a component, you could add it to the examples directory

Shai Perednik : yeah, I’ll try to make this into a component

Shai Perednik : I’m struggling w/ imgbb, I know that’s not your team’s tool, but any ideas on the error below? I’ve tried uploading the file and the base64 version:

    "status_code": 400,
    "error": {
        "message": "Can't get target upload source info",
        "code": 310,
        "context": "CHV\\UploadException"
    },
    "status_txt": "Bad Request"

Dylan Sather (Pipedream) : I haven’t seen that error before (maybe someone else here has). I’d suggest reaching out to their team / forum / StackOverflow on that one

Dylan Sather (Pipedream) : It seems like it might be having trouble finding the source file you’re trying to upload? That’s the first thing that comes to mind

Shai Perednik : yeah, it’s being a pain and the imgbb api doesn’t like the base64 version of the image either. I’ll have another go at this tomrrow