上传到Amazon S3后,PdfLib生成的PDF文件已损坏/不完整

时间:2013-01-08 12:33:07

标签: php pdf amazon-s3 pdflib

我正在使用PdfLib PHP扩展生成PDF文件。我启动一个新文件,将图像加载到其中,然后调用end_document来完成该文件。

一切正常,文件生成正确,但我正在尝试在生成后立即将文件上传到Amazon S3云(在生成文件的同一函数中)。该文件已上传但尚未完成,似乎上传了一个空的pdf。

// get a PDFLib object
$p = new PDFlib();

// determine filename
$pageFileName = $page->getPageNr() . '_' . sha1(microtime()) . '.pdf';

// determine local file path and S3 file path
$filePath = $this->fs->getPath(
    Dt_Util_FileStorage_Path::FILETYPE_SOURCEFILE,
    $pageFileName,
    $job
);

// start the document
if ($p->begin_document($filePath->getTmpPath(), "") == 0) {
    throw new Dt_Exception_DtException($p->get_errmsg(), 3, null);
}

// begin a new page inside the new document
$p->begin_page_ext($widthScreenResPixels, $heightScreenResPixels, "");

// load an image resource
$image = $p->load_image("auto", $imgfile, "");
if ($image == -1){
    throw new Exception("Error: " + $p->get_errmsg());
}

// load the image into the current page
$p->fit_image($image, 0, 0, "boxsize={" . $widthScreenResPixels . " " . $heightScreenResPixels . "} fitmethod=entire");

// end the page
$p->end_page_ext("");

// release the image
$p->close_image($image);

//write PDF file
$p->end_document("");

// sleep(5);

// upload the file to S3
$this->fs->putFile($filePath);

我在本地保存文件的位置包含应该的文件:图像被加载到文件中,文件大小约为600KB。上传的文件就像一个空的骨架,当我调用PdfLib-> begin_document时生成的文件,但在实际放入任何内容之前,我无法打开它,它的大小为104字节。

我在end_document之后和上传之前尝试了几秒钟,因为我认为PdfLib可能需要一些时间才能完成,但这没有效果,结果完全相同。

有没有人对如何解决这个问题有什么想法,导致这种情况的原因,在哪里寻找解决方案?

更新 问题似乎是我正在使用的S3 api类。我正在使用this one。使用官方SDK,上传按预期成功。我将继续使用官方SDK。最初的问题是,为什么它使用其他API类失败了。

0 个答案:

没有答案