stable

Clone or download

Read-only

File uploaded via tus can be downloaded via REST

Current users can see their own files they have just uploaded via tus. - expired files are not readable - other users' files are not readable To test you can use the following snippet. You will have to provide the path to the tus.js client library and update the field id to match your environment. Upload information (progress) is displayed on the devtools console. When the upload of the image is done then it is displayed on the page with the url returned by the server. ``` <input type="file" id="myfile"> <img id="image"> <script src="tus.js"></script> <script> document.getElementById('myfile').addEventListener('change', async (e) => { const field_id = 94; const file = e.target.files[0]; const post_response = await fetch(`/api/v1/tracker_fields/${field_id}/files`, { method: 'POST', credentials: 'same-origin', headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: file.name, file_size: file.size, file_type: file.type }) }); const post_response_body = await post_response.json(); const upload_href = post_response_body["upload_href"]; // Create a new tus upload const upload = new tus.Upload(file, { uploadUrl: upload_href, retryDelays: [0, 3000, 5000], metadata: { filename: file.name, filetype: file.type }, onError: function(error) { console.log("Failed because: " + error); }, onProgress: function(bytesUploaded, bytesTotal) { const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2); console.log(bytesUploaded, bytesTotal, percentage + "%"); }, onSuccess: function() { console.log(" %s uploaded to %s", upload.file.name, upload.url); document.getElementById('image').src = post_response_body["download_href"]; } }); // Start the upload upload.start(); }); </script> ``` Part of story #12964: drag'n drop images in tracker text areas Change-Id: Ic52c54dac80e3bf6f38a02985fc0e422566a688d

Modified Files

Name
M plugins/tracker/include/REST/v1/CreatedFileRepresentation.php +12 −2 Go to diff View file
M plugins/tracker/include/REST/v1/FileCreator.php +4 −4 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/AttachmentController.php +144 −0 Go to diff View file
M plugins/tracker/include/Tracker/FormElement/Field/File/Upload/FileOngoingUploadDao.php +2 −7 Go to diff View file
M plugins/tracker/include/Tracker/FormElement/Field/File/Upload/FileToUpload.php +11 −1 Go to diff View file
M plugins/tracker/include/Tracker/FormElement/Field/File/Upload/FileToUploadCreator.php +1 −1 Go to diff View file
M plugins/tracker/include/Tracker/FormElement/Field/File/Upload/UploadPathAllocator.php +5 −2 Go to diff View file
M plugins/tracker/include/Tracker/FormElement/Tracker_FormElementFactory.class.php +2 −2 Go to diff View file
M plugins/tracker/include/trackerPlugin.class.php +31 −0 Go to diff View file
A plugins/tracker/phpunit/Tracker/FormElement/Field/File/AttachmentControllerTest.php +593 −0 Go to diff View file
M plugins/tracker/phpunit/Tracker/FormElement/Field/File/Upload/EmptyFileToUploadFinisherTest.php +1 −1 Go to diff View file
A plugins/tracker/phpunit/Tracker/FormElement/Field/File/Upload/FileToUploadTest.php +38 −0 Go to diff View file
M plugins/tracker/tests/rest/TrackerFields/TrackerFieldsTest.php +11 −1 Go to diff View file