Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13970608
D8655.id20595.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D8655.id20595.diff
View Options
diff --git a/src/applications/files/config/PhabricatorFilesConfigOptions.php b/src/applications/files/config/PhabricatorFilesConfigOptions.php
--- a/src/applications/files/config/PhabricatorFilesConfigOptions.php
+++ b/src/applications/files/config/PhabricatorFilesConfigOptions.php
@@ -137,6 +137,19 @@
"Set this to a valid Amazon S3 bucket to store files there. You ".
"must also configure S3 access keys in the 'Amazon Web Services' ".
"group.")),
+ $this->newOption('storage.enable-public-uri', 'bool', false)
+ ->setSummary(pht('Configure usage of Amazon S3 public URI.'))
+ ->setDescription(
+ pht(
+ "Change this to allow certain applications to return file URLs ".
+ "that directly point to files stored on S3. This allows you ".
+ "to offload requests directly to Amazon and reduce load on ".
+ "the Phabricator server, at the cost of configuring Amazon S3 ".
+ "for public access.\n\n".
+ "NOTE: This currently only affects files which reside on the ".
+ "Amazon S3 storage engine.\n\n".
+ "NOTE: Currently Phragment's Conduit APIs are the only ".
+ "area that uses this functionality.")),
$this->newOption(
'storage.engine-selector',
'class',
diff --git a/src/applications/files/engine/PhabricatorFileStorageEngine.php b/src/applications/files/engine/PhabricatorFileStorageEngine.php
--- a/src/applications/files/engine/PhabricatorFileStorageEngine.php
+++ b/src/applications/files/engine/PhabricatorFileStorageEngine.php
@@ -82,6 +82,25 @@
/**
+ * Retrieve an absolute URI to which a download can be performed. This
+ * can be used to direct downloads to Amazon S3 for non-user
+ * applications (such as Conduit APIs).
+ *
+ * This URL should not be provided to end users, as the underlying storage
+ * engine will most likely not provide the correct semantics for
+ * browser-based downloads.
+ *
+ * Return null to indicate that no public URI is available.
+ *
+ * @param string The handle returned from @{method:writeFile} when the
+ * file was written.
+ * @return string An absolute URI from which a download can be performed.
+ * @task file
+ */
+ abstract public function retrieveFileURI($handle);
+
+
+ /**
* Delete the data for a file previously written by @{method:writeFile}.
*
* @param string The handle returned from @{method:writeFile} when the
diff --git a/src/applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php b/src/applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php
--- a/src/applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php
+++ b/src/applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php
@@ -68,6 +68,15 @@
/**
+ * Return null because there are no direct download URI.
+ * @task impl
+ */
+ public function retrieveFileURI($handle) {
+ return null;
+ }
+
+
+ /**
* Deletes the file from local disk, if it exists.
* @task impl
*/
diff --git a/src/applications/files/engine/PhabricatorMySQLFileStorageEngine.php b/src/applications/files/engine/PhabricatorMySQLFileStorageEngine.php
--- a/src/applications/files/engine/PhabricatorMySQLFileStorageEngine.php
+++ b/src/applications/files/engine/PhabricatorMySQLFileStorageEngine.php
@@ -52,6 +52,15 @@
/**
+ * Return null because there are no direct download URI.
+ * @task impl
+ */
+ public function retrieveFileURI($handle) {
+ return null;
+ }
+
+
+ /**
* Delete a blob from MySQL.
* @task impl
*/
diff --git a/src/applications/files/engine/PhabricatorS3FileStorageEngine.php b/src/applications/files/engine/PhabricatorS3FileStorageEngine.php
--- a/src/applications/files/engine/PhabricatorS3FileStorageEngine.php
+++ b/src/applications/files/engine/PhabricatorS3FileStorageEngine.php
@@ -69,6 +69,19 @@
/**
+ * Return absolute public URI for redirected download.
+ * @task impl
+ */
+ public function retrieveFileURI($handle) {
+ $base_uri = 'https://'.$this->getBucketName().'.s3.amazonaws.com/';
+ if ($base_uri === null) {
+ return null;
+ }
+ return $base_uri.$handle;
+ }
+
+
+ /**
* Delete a blob from Amazon S3.
*/
public function deleteFile($handle) {
diff --git a/src/applications/files/engine/PhabricatorTestStorageEngine.php b/src/applications/files/engine/PhabricatorTestStorageEngine.php
--- a/src/applications/files/engine/PhabricatorTestStorageEngine.php
+++ b/src/applications/files/engine/PhabricatorTestStorageEngine.php
@@ -28,6 +28,10 @@
throw new Exception("No such file with handle '{$handle}'!");
}
+ public function retrieveFileURI($handle) {
+ return null;
+ }
+
public function deleteFile($handle) {
AphrontWriteGuard::willWrite();
unset(self::$storage[$handle]);
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -502,6 +502,21 @@
return PhabricatorEnv::getCDNURI($path);
}
+ public function getMostDirectURI() {
+ if (PhabricatorEnv::getEnvConfig("storage.enable-public-uri")) {
+ // Redirect to the public URI if it's present. This means Conduit
+ // methods such as phragment.getstate will return URLs directly
+ // pointing to Amazon for downloading files.
+ $engine = $this->instantiateStorageEngine();
+ $uri = $engine->retrieveFileURI($this->getStorageHandle());
+ if ($uri === null) {
+ return $this->getDownloadURI();
+ }
+ } else {
+ return $this->getDownloadURI();
+ }
+ }
+
public function getInfoURI() {
return '/file/info/'.$this->getPHID().'/';
}
diff --git a/src/applications/phragment/conduit/ConduitAPI_phragment_queryfragments_Method.php b/src/applications/phragment/conduit/ConduitAPI_phragment_queryfragments_Method.php
--- a/src/applications/phragment/conduit/ConduitAPI_phragment_queryfragments_Method.php
+++ b/src/applications/phragment/conduit/ConduitAPI_phragment_queryfragments_Method.php
@@ -73,7 +73,7 @@
'path' => $cpath,
'hash' => $file->getContentHash(),
'version' => $child->getLatestVersion()->getSequence(),
- 'uri' => $file->getViewURI());
+ 'uri' => $file->getMostDirectURI());
}
$results[$path] = $result;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 18, 8:44 AM (3 w, 2 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6725938
Default Alt Text
D8655.id20595.diff (6 KB)
Attached To
Mode
D8655: Allow Phabricator to redirect to Amazon S3 for file downloads
Attached
Detach File
Event Timeline
Log In to Comment