Permalink
Browse files

Handle remote upload via pytio uploader tool

  • Loading branch information...
1 parent 09f5395 commit 84277b3d7355284f6f07df1cc2db9a3bcb6e4739 @ghecquet ghecquet committed Aug 24, 2016
Showing with 42 additions and 23 deletions.
  1. +2 −2 core/src/.htaccess
  2. +12 −7 core/src/plugins/core.mq/MqManager.php
  3. +28 −14 core/src/plugins/uploader.html/SimpleUpload.php
View
@@ -21,8 +21,8 @@ RewriteRule (.*) index.php [L]
# to make sure that authorization is transmitted.
# Just remove the # at the beginning of the line
-#SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
+SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</IfModule>
-AddType application/json .json
+AddType application/json .json
@@ -500,12 +500,14 @@ public function generateCaddyFile($params) {
// Getting URLs of the Pydio system
$serverURL = ApplicationState::detectServerURL();
$tokenURL = $serverURL . "?get_action=keystore_generate_auth_token";
- $authURL = $serverURL . "/api/pydio/ws_authenticate?key=" . $configs["WS_SERVER_ADMIN"];
// Websocket Server Config
$active = $params["WS_ACTIVE"];
if ($active) {
+
+ $authURL = $serverURL . "/api/pydio/ws_authenticate?key=" . $configs["WS_SERVER_ADMIN"];
+
$host = $params["WS_HOST"];
$port = $params["WS_PORT"];
$secure = $params["WS_SECURE"];
@@ -525,6 +527,9 @@ public function generateCaddyFile($params) {
$active = $params["UPLOAD_ACTIVE"];
if ($active) {
+
+ $authURL = $serverURL . "/api/{repo}/upload/put";
+
$host = $params["UPLOAD_HOST"];
$port = $params["UPLOAD_PORT"];
$secure = $params["UPLOAD_SECURE"];
@@ -535,12 +540,12 @@ public function generateCaddyFile($params) {
(array)$hosts[$key],
[
"header " . $path => ["{\n" .
- "\tAccess-Control-Allow-Origin " . $serverURL . "\n" .
- "\tAccess-Control-Request-Headers *\n" .
- "\tAccess-Control-Allow-Methods POST\n" .
- "\tAccess-Control-Allow-Headers Range\n" .
- "\tAccess-Control-Allow-Credentials true\n" .
- "}"
+ "\t\tAccess-Control-Allow-Origin " . $serverURL . "\n" .
+ "\t\tAccess-Control-Request-Headers *\n" .
+ "\t\tAccess-Control-Allow-Methods POST\n" .
+ "\t\tAccess-Control-Allow-Headers Range\n" .
+ "\t\tAccess-Control-Allow-Credentials true\n" .
+ "\t}"
],
"pydioauth " . $path => [$authURL, $tokenURL . "&device=upload"],
"pydioupload " . $path => []
@@ -73,19 +73,6 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
return;
}
- // Mandatory headers
- if (!isset($serverData['CONTENT_LENGTH'], $serverData['HTTP_X_FILE_NAME'])) {
- throw new PydioException("Warning, missing headers!");
- }
-
- $fileNameH = $serverData['HTTP_X_FILE_NAME'];
- $fileSizeH = (int)$serverData['HTTP_X_FILE_SIZE'];
- // Clean up dir name (backward compat)
- if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
- $httpVars["dir"] = "/";
- }
- $clientFileName = TextEncoder::fromUTF8(basename($fileNameH));
-
$this->logDebug("SimpleUpload::preProcess", $httpVars);
// Setting the stream data
@@ -97,6 +84,16 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
exit('Warning, wrong headers');
}
+ $fileNameH = $serverData['HTTP_X_FILE_NAME'];
+ $fileSizeH = (int)$serverData['HTTP_X_FILE_SIZE'];
+
+ // Clean up dir name (backward compat)
+ if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
+ $httpVars["dir"] = "/";
+ }
+
+ $clientFileName = TextEncoder::fromUTF8(basename($fileNameH));
+
// Setting the stream to point to the file location
$streamOrFile = $serverData['HTTP_X_FILE_TMP_LOCATION'];
$errorStatus = UPLOAD_ERR_OK;
@@ -111,16 +108,33 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
} else if(isSet($serverData['HTTP_X_FILE_DIRECT_UPLOAD'])){
+ // Mandatory headers
$externalUploadStatus = $serverData['HTTP_X_FILE_DIRECT_UPLOAD'];
if(!ExternalUploadedFile::isValidStatus($externalUploadStatus)){
throw new PydioException("Unrecognized direct upload status ". $externalUploadStatus);
}
- $uploadedFile = new ExternalUploadedFile($externalUploadStatus, $fileSizeH, $fileNameH);
+ $uploadedFile = new ExternalUploadedFile($externalUploadStatus, 1, "fake-name");
} else {
// The file is the post data stream
+ // Mandatory headers
+ if (!isset($serverData['CONTENT_LENGTH'], $serverData['HTTP_X_FILE_NAME'])) {
+ throw new PydioException("Warning, missing headers!");
+ }
+
+ $fileNameH = $serverData['HTTP_X_FILE_NAME'];
+ $fileSizeH = (int)$serverData['HTTP_X_FILE_SIZE'];
+
+ // Clean up dir name (backward compat)
+ if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
+ $httpVars["dir"] = "/";
+ }
+
+ $clientFileName = TextEncoder::fromUTF8(basename($fileNameH));
+
+
// Checking headers
if (isSet($serverData['HTTP_X_FILE_SIZE'])) {
if ($serverData['CONTENT_LENGTH'] != $serverData['HTTP_X_FILE_SIZE']) {

0 comments on commit 84277b3

Please sign in to comment.