Simple haserl script for ds media library clip upload.
The script requires a form data request with uploadfile
field.
Example:
curl -X POST -F uploadfile=@clip3m.mp3 http://192.168.1.150/cgi-bin/upload-clip.hs -v
{"success":true,"code":200,"location":"/tmp/5a99ea9dfe1d.mp3","total_size":3383,"size_limit":102400}
Once the file upload completed, the script returns loaction of the file
in the tmp directory and current memory usage. Note that the file name
is discarded and renamed to random hex string.
Script limits one file upload to 2MB and user clips storage to 100MB.
One file size limit is handled by haserl. In this case the haserl
returns an error with XML body:
< HTTP/1.1 413 Request Entity Too Large
< Content-Type: text/html
< Content-Length: 375
< Connection: close
< Date: Sun, 20 Mar 2022 19:04:04 GMT
< Server: lighttpd/1.4.48
<
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>413 - Request Entity Too Large</title>
</head>
<body>
<h1>413 - Request Entity Too Large</h1>
</body>
</html>
Initially we wanted to control the file limit in the script to return
consistent JSON error message, but haserl requires some limit, so in fact
we would only move the limit, but will not avoid in the end the haserl
error in xml format. Saying that, we recommend to check an error code
first, then try to parse the response based on the content type header.
When the memory is exhausted, the script returns an error:
{"success":false,"code":429,"message":"Memory space exhausted","total_size":101000,"size_limit":102400}
Supported methods: GET, POST.
GET request returns information about the memory usage in kB.
{"success":true,"code":200,"total_size":3383,"size_limit":102400}
POST is dedicated for the file upload.
{"success":true,"code":200,"location":"/tmp/65eaaa80f6f1.mp3","total_size":3383,"size_limit":102400}
Errors:
- 200 - Ok
- 405 - Method not supported
- 413 - Request Entity Too Large (see haserl error)
- 429 - Memory space exhausted
- 500 - Internal error