dongliang1865 2016-10-13 04:39
浏览 88

PHP解码Base64 PDF上载到CMIS服务器

I am developing a REST API using Laravel 5.1 that has use case as following: receive a base 64 decoded PDF, and return a workspace ID of a Document Management System (DMS) from the uploaded file. The DMS service that I use in this case is Alfresco.

Current Condition

The application succeed to receive base 64 string and decode it to a file. I store the decoded file into system temporary directory, and try to upload it to the Alfresco. I have previously built function that receive a file from a form request to be stored in the Alfresco, and it works. Here is the declaration and parameters stated in the function:

public static function uploadDocument(
    $doc,               // <-- Okay by form request, not okay by the API decoded file
    $user,              // credential
    $password,          // credential
    $params = array()   // array that contains ACE
    )
{

However, when I tried to use the same function with different document source, it failed. By different document source, I mean the source comes from the decoded base 64, and can be seen as follow:

    // Decrypt base64
    $fileData = base64_decode($request->input('file'));

    // Save the decoded file to a temp directory
    $tmpDir = sys_get_temp_dir();
    $fileName = $request->input("fileName");
    $pdfFile = fopen("$tmpDir/$fileName", 'w');
    fwrite ($pdfFile, $fileData);

    // Upload the decrypted file to the Alfresco
    $alfUsername = Config::get('alfresco.CMIS_BROWSER_USER');
    $alfPassword = Config::get('alfresco.CMIS_BROWSER_PASSWORD');
    $assignees = ['assignees' => []];
    $alfObjId = Alfresco::uploadDocument(
        $pdfFile,
        $alfUsername,
        $alfPassword,
        $assignees
    );

    fclose ($pdfFile);

The Error

Call to a member function getClientOriginalName() on resource

That refers to this line:

$uniqueFileName = $alfresco
    ->getUniqueFileName([
        'path' => $path,
        'filename' => $doc->getClientOriginalName(), // <-- This line
        'session' => $session
    ]);

Error screenshot

The Question

  1. Can one uploads a decoded base 64 file to another service without using temporary file?
  2. How can I convert the decoded file into a multipart form request or similar, in order that my upload function could consume?

Thank you.

  • 写回答

1条回答 默认 最新

  • dounao1856 2016-10-13 04:51
    关注

    Well, sure you can call other service without saving a temporary file. If the file is already in memory as a string you could use curl to send a new request sending the string as data. Using curl to create a request you could set the content type header to multipart form data

    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端