Merge remote-tracking branch 'origin/master' into tus-integration
diff --git a/app/libraries/ExperimentUtilities.php b/app/libraries/ExperimentUtilities.php
index dde5f97..253a3d8 100755
--- a/app/libraries/ExperimentUtilities.php
+++ b/app/libraries/ExperimentUtilities.php
@@ -418,24 +418,28 @@
}
}
} elseif ($applicationInput->type == DataType::URI) {
- if ($_FILES[$applicationInput->sanitizedFormName]['name']) {
- $file = $_FILES[$applicationInput->sanitizedFormName];
- if ($file['error'] != 0) {
- throw new Exception("Failure occurred while uploading file '"
- . $file['name'] . "'. File upload error code is " . $file['error'] . ".");
- }
+ if (isset($_POST[$applicationInput->sanitizedFormName]) && (trim($_POST[$applicationInput->sanitizedFormName]) != '')) {
- //FIX - AIRAVATA - 2674
- //Replaced spaces with Underscore
- $file['name'] = str_replace(' ', '_', $file['name']);
- //
+ Log::info('Processing input ' . $applicationInput->sanitizedFormName);
+
+ $tus_data_dir = "/data/gateway-user-data/tus-temp-dir/";
+ $tus_download_url = trim($_POST[$applicationInput->sanitizedFormName]);
+ $file_uuid = explode("/", $tus_download_url)[4];
+ $tus_bin_file = $tus_data_dir . $file_uuid . ".bin";
+ $tus_info_file = $tus_data_dir . $file_uuid . ".info";
+ $tus_info_file_as_str = file_get_contents($tus_info_file);
+ $tus_info_file_as_arr = json_decode($tus_info_file_as_str, true);
+ $file_name = $tus_info_file_as_arr["MetaData"]["filename"];
+ $file_name = str_replace(' ', '_', $file_name);
+
// move file to experiment data directory
//
+ $filePath = "";
if (!empty($applicationInput->value)) {
$filePath = $experimentFilePath . $applicationInput->value;
} else {
- $filePath = $experimentFilePath . $file['name'];
+ $filePath = $experimentFilePath . $file_name;
}
// check if file already exists
@@ -445,10 +449,23 @@
CommonUtilities::print_warning_message('Uploaded file already exists! Overwriting...');
}
- $moveFile = move_uploaded_file($file['tmp_name'], $filePath);
+ Log::info('Starting the file movement from ' . $tus_bin_file . ' to ' . $filePath);
+
+ $bin_file_size = filesize($tus_bin_file) / (1000 * 1000 * 1000);
+ Log::info('File size ' . $bin_file_size);
+
+ if ($bin_file_size > 1) {
+ Log::info("Creating sym link as the file size is too large");
+ $moveFile = symlink($tus_bin_file, $filePath);
+ } else {
+ Log::info("Copying the file ...");
+ $moveFile = copy($tus_bin_file, $filePath);
+ }
+
+ Log::info('File moved to storage ' . $filePath);
if (!$moveFile) {
- CommonUtilities::print_error_message('<p>Error moving uploaded file ' . $file['name'] . '!
+ CommonUtilities::print_error_message('<p>Error moving uploaded file ' . $file_name . '!
Please try again later or report a bug using the link in the Help menu.</p>');
$experimentAssemblySuccessful = false;
}
@@ -563,7 +580,7 @@
$experimentName = preg_replace('/[^a-zA-Z0-9]+/', '_', $experimentName);
ExperimentUtilities::$relativeExperimentDataDir = "/" . Session::get('username') . "/" . $projectId . "/"
- . $experimentName . time() . '/';
+ . $experimentName . time() . '/';
ExperimentUtilities::$experimentPath = Config::get('pga_config.airavata')['experiment-data-absolute-path'] .
ExperimentUtilities::$relativeExperimentDataDir;
} while (is_dir(ExperimentUtilities::$experimentPath)); // if dir already exists, try again
@@ -906,12 +923,12 @@
echo '<div class="form-group">
<label for="experiment-input">' . $input->name . '</label>
<input class="form-control" type="text" name="' . $input->sanitizedFormName .
- '" id="' . $input->sanitizedFormName . '" ' . $required . '>
+ '" id="' . $input->sanitizedFormName . '" ' . $required . '>
<p class="help-block">' . $input->userFriendlyDescription . '</p>
</div>';
break;
}else{
- echo '<div class="form-group">
+ /*echo '<div class="form-group">
<label for="experiment-input">' . $input->name . '</label>
<div data-file-id="' . $input->sanitizedFormName . '" class="readBytesButtons btn btn-default btn-xs"
data-toggle="modal" style="float: right">view file</div>
@@ -921,7 +938,31 @@
<div class="file-upload-max-size">Max Upload Size: ' . $allowedFileSize .'M</div>
</div>
<p class="help-block">' . $input->userFriendlyDescription . '</p>
- </div>';
+ </div>';*/
+ echo '
+ <label for="experiment-input">' . $input->name . '</label>
+ <div class="grid">
+ <div class="column-full">
+ <input type="hidden" name="' . $input->sanitizedFormName . '" id="' . $input->sanitizedFormName . '"/>
+ <div class="UppyInput" id="input-' . $input->sanitizedFormName . '"></div>
+ <div class="UppyInput-Progress" id="progress-'. $input->sanitizedFormName .'"></div>
+ </div>
+ </div>';
+ echo '<script>
+ var uppy = Uppy.Core({debug: true, autoProceed: true})
+ .use(Uppy.FileInput, { target: "#input-' . $input->sanitizedFormName . '", pretty: false })
+ .use(Uppy.StatusBar, {
+ target: "#progress-' . $input->sanitizedFormName . '",
+ hideUploadButton: true,
+ hideAfterFinish: false
+ })
+ .use(Uppy.Tus, {endpoint: "https://tus.scigap.org/files/"})
+
+ uppy.on("complete", (result) => {
+ console.log("Upload complete! We’ve uploaded these files:", result.successful)
+ document.getElementById("'. $input->sanitizedFormName .'").value = result.successful[0].response.uploadURL;
+ })
+ </script>';
break;
}
case DataType::URI_COLLECTION:
diff --git a/app/views/layout/fixed-header.blade.php b/app/views/layout/fixed-header.blade.php
index c03e167..997c0b3 100644
--- a/app/views/layout/fixed-header.blade.php
+++ b/app/views/layout/fixed-header.blade.php
@@ -8,6 +8,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="resources/assets/favicon.ico" type="image/x-icon">
+ <link href="https://transloadit.edgly.net/releases/uppy/v1.0.0/uppy.min.css" rel="stylesheet">
+ <script src="https://transloadit.edgly.net/releases/uppy/v1.0.0/uppy.min.js"></script>
+
{{ HTML::style('css/bootstrap.min.css')}}