getHttpUploadPostParams() public static method

Get upload POST parameters for form uploads
public static getHttpUploadPostParams ( string $bucket, string $uriPrefix = '', constant $acl = self::ACL_PRIVATE, integer $lifetime = 3600, integer $maxFileSize = 5242880, string $successRedirect = "201", array $amzHeaders = [], array $headers = [], boolean $flashVars = false ) : object
$bucket string Bucket name
$uriPrefix string Object URI prefix
$acl constant ACL constant
$lifetime integer Lifetime in seconds
$maxFileSize integer Maximum filesize in bytes (default 5MB)
$successRedirect string Redirect URL or 200 / 201 status code
$amzHeaders array Array of x-amz-meta-* headers
$headers array Array of request headers or content type as a string
$flashVars boolean Includes additional "Filename" variable posted by Flash
return object
Ejemplo n.º 1
0
 public static function generateUploadPOSTParams($item, Zotero_StorageFileInfo $info, $useItemContentType = false)
 {
     if (strlen($info->hash) != 32) {
         throw new Exception("Invalid MD5 hash '{$info->md5}'");
     }
     if (!$item->isAttachment()) {
         throw new Exception("Item {$item->id} is not an attachment");
     }
     $linkMode = $item->attachmentLinkMode;
     switch ($linkMode) {
         // TODO: get these constants from somewhere
         case 0:
         case 1:
             break;
         default:
             throw new Exception("Attachment with link mode {$linkMode} cannot be uploaded");
     }
     $lifetime = 3600;
     $path = self::getPathPrefix($info->hash, $info->zip);
     $contentMD5 = '';
     for ($i = 0; $i < strlen($info->hash); $i += 2) {
         $contentMD5 .= chr(hexdec(substr($info->hash, $i, 2)));
     }
     $contentMD5 = base64_encode($contentMD5);
     if ($useItemContentType) {
         if ($info->zip) {
             $contentType = "application/octet-stream";
         } else {
             $contentType = $item->attachmentMIMEType;
         }
     } else {
         $contentType = $info->contentType;
     }
     $metaHeaders = array();
     $requestHeaders = array('Content-Type' => $contentType, 'Content-MD5' => $contentMD5);
     self::requireLibrary();
     S3::setAuth(Z_CONFIG::$S3_ACCESS_KEY, Z_CONFIG::$S3_SECRET_KEY);
     $params = S3::getHttpUploadPostParams(Z_CONFIG::$S3_BUCKET, $path, S3::ACL_PRIVATE, $lifetime, $info->size + 262144, 201, $metaHeaders, $requestHeaders, $info->filename);
     return $params;
 }
Ejemplo n.º 2
0
}
// Pointless without your keys!
if (awsAccessKey == 'change-this' || awsSecretKey == 'change-this') {
    exit("\nERROR: AWS access information required\n\nPlease edit the following lines in this file:\n\n" . "define('awsAccessKey', 'change-me');\ndefine('awsSecretKey', 'change-me');\n\n");
}
S3::setAuth(awsAccessKey, awsSecretKey);
$bucket = 'upload-bucket';
$path = 'myfiles/';
// Can be empty ''
$lifetime = 3600;
// Period for which the parameters are valid
$maxFileSize = 1024 * 1024 * 50;
// 50 MB
$metaHeaders = array('uid' => 123);
$requestHeaders = array('Content-Type' => 'application/octet-stream', 'Content-Disposition' => 'attachment; filename=${filename}');
$params = S3::getHttpUploadPostParams($bucket, $path, S3::ACL_PUBLIC_READ, $lifetime, $maxFileSize, 201, $metaHeaders, $requestHeaders, false);
$uploadURL = 'https://' . $bucket . '.s3.amazonaws.com/';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>S3 Form Upload</title>
</head>
<body>
    <form method="post" action="<?php 
echo $uploadURL;
?>
" enctype="multipart/form-data">
<?php 
foreach ($params as $p => $v) {
    echo "        <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";