我正在尝试从原始PDF字符串创建一个临时PDF文件。
这是我的输入,通过API(JSON)发送:
{
"name": "pdffilename.pdf",
"content": "%PDF-1.2 [.......]%%EOF"
}
-
这个
"content"
字符串是实际的PDF原始数据字符串。
这是我的控制器,处理API请求:
/**
* Function to convert a PDF file to text
*/
public function PDFtoText(Request $request)
{
$name = $request->name;
$content = $request->content;
//Save PDF file on the server (temp files).
$pdf = Storage::disk('local')->put('/temp_files/' . $name, $content);
return response()->json([
'result' => "Success"
], 200);
}
将在中创建一个实际文件
temp_files
文件夹,名称为
pdffilename.pdf
.但是我无法打开文件,因为它说文件“已损坏”。
我做错了什么?