forked from webhooksite/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_upload.ws
33 lines (29 loc) · 835 Bytes
/
csv_upload.ws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
url = var('request.url')
if (var('$request.method$') != 'POST') {
respond('
<html>
<head><title>Upload CSV</title></head>
<body>
<h1>Upload CSV</h1>
<form action="{}" method="POST" enctype="multipart/form-data">
<input type="file" name="file"/>
<button type="submit">Upload</button>
</form>
</body>
</html>
'.format(url))
}
array = csv_to_array(var('request.file.file.content'), ',', 0)
if (!array or array.length() < 2) {
respond('
<h1>Could not parse CSV</h1>
<a href="{}">Upload again</a>
'.format(url));
}
respond('
<h1>Upload successful</h1>
<pre>{}</pre>
<p>
<a href="{}">Upload again</a>
</p>
'.format(json_encode(array), url))