putObject($input, $bucket, $uri); } else { // Get an upload session $uploadSession = $s3->startMultipart($input, $bucket, $uri); // This array holds the etags of uploaded parts. Used by finalizeMultipart. $eTags = []; $partNumber = 1; while (true) { // We need to create a new input for each upload chunk if ($useString) { $input = Input::createFromData($sourceData); } else { $input = Input::createFromFile($sourceFile); } $input->setUploadID($uploadSession); $input->setEtags($eTags); $input->setPartNumber($partNumber); $etag = $s3->uploadMultipart($input, $bucket, $uri, [], static::$uploadChunkSize); // If the result was null we have no more file parts to process. if (is_null($etag)) { break; } // Append the etag to the etags array $eTags[] = $etag; // Set the etags array in the Input object (required by finalizeMultipart) $input->setEtags($eTags); $partNumber++; } static::$numberOfChunks = count($eTags); // Finalize the multipart upload. Tells Amazon to construct the file from the uploaded parts. $s3->finalizeMultipart($input, $bucket, $uri); } // Tentatively accept that this method succeeded. $result = true; // Should I download the file and compare its contents? if (static::$downloadAfter) { if ($useString) { // Download the data. Throws exception if it fails. $downloadedData = $s3->getObject($bucket, $uri); // Compare the file contents. $result = static::areStringsEqual($sourceData, $downloadedData); } else { // Download the data. Throws exception if it fails. $downloadedFile = tempnam(static::getTempFolder(), 'as3'); $s3->getObject($bucket, $uri, $downloadedFile); // Compare the file contents. $result = static::areFilesEqual($sourceFile, $downloadedFile); @unlink($downloadedFile); } } // Remove the local files if (!$useString) { @unlink($sourceFile); } // Should I delete the remotely stored file? if (static::$deleteRemote) { // Delete the remote file. Throws exception if it fails. $s3->deleteObject($bucket, $uri); } return $result; } }