我已经构建了一个 ajax 上传器,可以将文件直接上传到 S3,它运行完美,但我感到困惑的是它实际上是如何工作的。我对文档中的显示方式采取了不同的方法,不是指定 sourceFile,而是在元数据中指定文件名。没有发送文件位置。
我在用着AWS SDK 2.4.3
$client = S3Client::factory(array(
'key' => AWS_KEY,
'secret' => AWS_SECRET
));
$extension = pathinfo($this->request->query['fileInfo']['name'], PATHINFO_EXTENSION);
$model = $client->createMultipartUpload(array(
'Bucket' => AWS_BUCKET_NAME,
'Key' => uniqid() . '.' . $extension, // Files don't share same name
'ContentType' => $this->request->query['fileInfo']['type'], // image/png
'Metadata' => $this->request->query['fileInfo']
));
$this->请求->查询['fileInfo']
array(
'name' => "image.png",
'type' => "image/png",
'size' => 196292,
'lastModifiedDate' => Wed Aug 20 2014 15:02:29 GMT+1200 (NZST)
);
登录上传部分
$command = $client->getCommand('UploadPart',
array(
'Bucket' => AWS_BUCKET_NAME,
'Key' => $this->request->query['sendBackData']['key'], // 53fd39a185f43.png
'UploadId' => $this->request->query['sendBackData']['uploadId'], // hSJuBm3dWCMM1b....
'PartNumber' => $this->request->query['partNumber'],
'ContentLength' => $this->request->query['contentLength']
));
$request = $command->prepare();
$client->dispatch('command.before_send', array('command' => $command));
$request->removeHeader('User-Agent');
$request->setHeader('x-amz-date', gmdate(DateFormat::RFC2822));
$client->dispatch('request.before_send', array('request' => $request));
任何地方都没有对临时文件路径的引用,我尝试过深入研究 SDK,但似乎找不到任何显示查找文件方法的内容。此外,由于这是通过 AJAX 发送的,因此不会创建临时文件。
删除Metadata
ContentType
并分配一个随机数Key
in the CreateMultipartUpload
仍然上传文件,只是以 Key 中指定的名称结束...让另外两个开发人员查看它,但都无法弄清楚它是如何工作的。