Changeset View
Changeset View
Standalone View
Standalone View
src/upload/ArcanistFileUploader.php
<?php | <?php | ||||
/** | /** | ||||
* Upload a list of @{class:ArcanistFileDataRef} objects over Conduit. | * Upload a list of @{class:ArcanistFileDataRef} objects over Conduit. | ||||
* | * | ||||
* // Create a new uploader. | * // Create a new uploader. | ||||
* $uploader = id(new ArcanistFileUploader()) | * $uploader = (new ArcanistFileUploader()) | ||||
* ->setConduitEngine($conduit); | * ->setConduitEngine($conduit); | ||||
* | * | ||||
* // Queue one or more files to be uploaded. | * // Queue one or more files to be uploaded. | ||||
* $file = id(new ArcanistFileDataRef()) | * $file = (new ArcanistFileDataRef()) | ||||
* ->setName('example.jpg') | * ->setName('example.jpg') | ||||
* ->setPath('/path/to/example.jpg'); | * ->setPath('/path/to/example.jpg'); | ||||
* $uploader->addFile($file); | * $uploader->addFile($file); | ||||
* | * | ||||
* // Upload the files. | * // Upload the files. | ||||
* $files = $uploader->uploadFiles(); | * $files = $uploader->uploadFiles(); | ||||
* | * | ||||
* For details about building file references, see @{class:ArcanistFileDataRef}. | * For details about building file references, see @{class:ArcanistFileDataRef}. | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | foreach ($files as $key => $file) { | ||||
$delete_after = $file->getDeleteAfterEpoch(); | $delete_after = $file->getDeleteAfterEpoch(); | ||||
if ($delete_after !== null) { | if ($delete_after !== null) { | ||||
$params['deleteAfterEpoch'] = $delete_after; | $params['deleteAfterEpoch'] = $delete_after; | ||||
} | } | ||||
$futures[$key] = $conduit->newFuture('file.allocate', $params); | $futures[$key] = $conduit->newFuture('file.allocate', $params); | ||||
} | } | ||||
$iterator = id(new FutureIterator($futures))->limit(4); | $iterator = (new FutureIterator($futures))->limit(4); | ||||
$chunks = array(); | $chunks = array(); | ||||
foreach ($iterator as $key => $future) { | foreach ($iterator as $key => $future) { | ||||
try { | try { | ||||
$result = $future->resolve(); | $result = $future->resolve(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
// The most likely cause for a failure here is that the server does | // The most likely cause for a failure here is that the server does | ||||
// not support `file.allocate`. In this case, we'll try the older | // not support `file.allocate`. In this case, we'll try the older | ||||
// upload method below. | // upload method below. | ||||
▲ Show 20 Lines • Show All 187 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0