+PUT/file/{name}
+
+
+### Description
+
+Upload a file.
+
+### Parameters
+
+Param | Type | Required | Location | Maximum Size | Default | Description
+----------|---------|----------|---------------|------------------------------|---------|-----------------------------------
+name | string | true | URL | 255 characters | none | Name of the file to upload
+anonymous | boolean | false | URL parameter | N/A | false | File is not linked to user if true
+file | file | true | request body | Depends on user subscription | none | File to upload
+
+### Returns
+
+HTTP 200: OK
+```
+{
+ "id": "abc123" // ID of the newly uploaded file
+}
+```
+
+HTTP 422: Unprocessable Entity
+```
+{
+ "success": false,
+ "value": "no_file",
+ "message": "The file does not exist or is empty."
+}
+```
+
+HTTP 500: Internal Server Error
+```
+{
+ "success": false,
+ "value": "internal",
+ "message": "An internal server error occurred."
+}
+```
+
+HTTP 413: Payload Too Large
+```
+{
+ "success": false,
+ "value": "file_too_large",
+ "message": "The file you tried to upload is too large"
+}
+```
+
+HTTP 500: Internal Server Error
+```
+{
+ "success": false,
+ "value": "writing",
+ "message": "Something went wrong while writing the file to disk, the server may be out of storage space."
+}
+```
+
+HTTP 413: Payload Too Large
+```
+{
+ "success": false,
+ "value": "name_too_long",
+ "message": "File Name is too long, Max 255 characters allowed."
+}
+```
+
+
+
GET/file/{id}
diff --git a/svelte/src/home_page/UploadProgressBar.svelte b/svelte/src/home_page/UploadProgressBar.svelte
index 1249776..8bcd25e 100644
--- a/svelte/src/home_page/UploadProgressBar.svelte
+++ b/svelte/src/home_page/UploadProgressBar.svelte
@@ -94,11 +94,8 @@ export const start = () => {
stats_interval = setInterval(on_progress, stats_interval_ms)
}
- let form = new FormData();
- form.append('file', job.file, job.name);
-
let xhr = new XMLHttpRequest();
- xhr.open("POST", window.api_endpoint+"/file", true);
+ xhr.open("PUT", window.api_endpoint+"/file/"+encodeURIComponent(job.name), true);
xhr.timeout = 86400000; // 24 hours, to account for slow connections
xhr.upload.addEventListener("progress", evt => {
@@ -142,6 +139,8 @@ export const start = () => {
tries++
setTimeout(start, 5000)
}
+ } else if (xhr.status === 0) {
+ on_failure("request_failed", "Your request did not arrive, or the server blocked the request")
} else {
// Request did not arrive
if (tries < 3) {
@@ -155,7 +154,7 @@ export const start = () => {
}
};
- xhr.send(form);
+ xhr.send(job.file);
}
const add_upload_history = id => {