Ejemplo n.º 1
0
 public function SignRequest($req, $mimetype = null, $type = Conf::HEAD_FIELD_CHECK)
 {
     $url = $req->URL;
     $url = parse_url($url['path']);
     $data = '';
     $data .= strtoupper($req->METHOD) . "\n";
     $data .= HTTP_Utils::UCloud_Header_Get($req->Header, 'Content-MD5') . "\n";
     if ($mimetype) {
         $data .= $mimetype . "\n";
     } else {
         $data .= HTTP_Utils::UCloud_Header_Get($req->Header, 'Content-Type') . "\n";
     }
     if ($type === Conf::HEAD_FIELD_CHECK) {
         $data .= HTTP_Utils::UCloud_Header_Get($req->Header, 'Date') . "\n";
     } else {
         $data .= HTTP_Utils::UCloud_Header_Get($req->Header, 'Expires') . "\n";
     }
     $data .= Digest::CanonicalizedResource($req->Bucket, $req->Key);
     $data .= Digest::CanonicalizedUCloudHeaders($req->Header);
     return $this->Sign($data);
 }
Ejemplo n.º 2
0
 function UCloud_MultipartForm($bucket, $key, $file)
 {
     $action_type = ActionType::POSTFILE;
     $err = Utils::CheckConfig(ActionType::POSTFILE);
     if ($err != null) {
         return array(null, $err);
     }
     $f = @fopen($file, "r");
     if (!$f) {
         return array(null, new UCloud_Error(-1, -1, "open {$file} error"));
     }
     $host = $bucket . Conf::UCLOUD_PROXY_SUFFIX;
     $path = "";
     $content = @fread($f, filesize($file));
     if ($content == FALSE) {
         if (feof($f)) {
             break;
         }
         fclose($f);
         return array(null, new UCloud_Error(0, -1, "read file error"));
     }
     list($mimetype, $err) = Utils::GetFileMimeType($file);
     if ($err) {
         fclose($f);
         return array("", $err);
     }
     $req = new HTTP_Request('POST', array('host' => $host, 'path' => $path), $content, $bucket, $key, $action_type);
     $req->Header['Expect'] = '';
     $token = Digest::UCloud_SignRequest(null, $req, $mimetype);
     $fields = array('Authorization' => $token, 'FileName' => $key);
     $files = array('files' => array('file', $file, $content, $mimetype));
     $client = new UCloud_AuthHttpClient(null, NO_AUTH_CHECK);
     list($data, $err) = HTTP_Utils::UCloud_Client_CallWithMultipartForm($client, $req, $fields, $files);
     fclose($f);
     return array($data, $err);
 }
Ejemplo n.º 3
0
 public function __construct($auth, $mimetype = null, $type = Conf::HEAD_FIELD_CHECK)
 {
     $this->Type = $type;
     $this->MimeType = $mimetype;
     $this->Auth = Digest::UCloud_MakeAuth($auth, $type);
 }