更改文件内容 - Alfresco

Change content of file - Alfresco

我有一个 Custom Document Library ActionAlfresco 个文件,当我按下这个按钮时,会打开一个带有小程序 (javascript) 的新页面来对文件进行更改,但是我我正在 base64 和屏幕上的 "appear" 中进行修改:

var stringPDF = "<object data=\"data:application/pdf;base64," +
JSON.parse(pdfbase64).message + "\"
type=\"application/pdf\"width=\"100%\"
height=\"100%\"></object>";$("#pdfTexto").html(stringPDF);

但我真正需要的是更改文件,因为当再次存储库时,那里必须更改,而不仅仅是显示。如何通过更改将现有文件的内容更改为新内容?

我使用此 URL 获取文件:

http://localhost:8080/share/proxy/alfresco/slingshot/node/content/workspace/SpacesStore/21384098-19dc-4d3f-bcc1-9fdc647c05dc/latexexemplo.pdf

然后我转换为 base64...并进行更改...

但是如果我想做一个POST来改变内容,我该怎么做呢?

提前致谢。

正如我在 my response to this question 中提到的:

The fastest and easiest way to achieve that is to leverage the RESTfull API

This will also ensure compatibility with new versions of alfresco.

Note that you need to provide the noderef for the document to update in the form property updatenoderef and that the property majorversion is a boolean flag to specify if the new version is a minor/major version of the document.

Here is a sample code that might help you with your usecase:

        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost uploadFile = new HttpPost(<alfresco-service-uri>+"/api/upload?alf_ticket="+<al-ticket>);

        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.addTextBody("username", "<username>", ContentType.TEXT_PLAIN);
        builder.addTextBody("updatenoderef", <noderef>, ContentType.TEXT_PLAIN);
        builder.addTextBody("...", "...", ContentType.TEXT_PLAIN);
        builder.addBinaryBody("filedata", <InputStream>, ContentType.DEFAULT_BINARY, <filename>);
        HttpEntity multipart = builder.build();

        uploadFile.setEntity(multipart);

        CloseableHttpResponse response = httpClient.execute(uploadFile);

        String responseString = IOUtils.toString(response.getEntity().getContent(), "UTF-8"); 
        JSONObject responseJson = new JSONObject(responseString);
        if (response.getStatusLine().getStatusCode()!=200){
            throw new Exception("Couldn't upload file to the repository, webscript response :" + responseString );
        }

Note 1: You need to replace these tockens <*> with your own values/vars

Note 2: If you have problem retrieving a ticket, check this link, or this one

注意3:要在JavaScript而不是java中执行此操作,请访问this link并尝试使用js来post 我按照指示引用的参数 !

注意 4:由于您正在共享,因此您很可能已通过身份验证。

如果是这种情况,您可以通过 share 中的代理端点访问您的 alfresco 存储库,所有请求在转发到您的存储库之前都会附加身份验证票证!

换句话说,使用这个端点:

/share/proxy/alfresco/api/upload

而不是:

/alfresco/service/api/upload

而且您甚至不必在请求中附加票证。

您需要按照这些步骤来实现您想要的。

1) 读取文件:

要显示已上传的 PDF 文件的内容,您需要阅读文件的内容。您可以使用以下 API 调用成功完成此操作。

http://localhost:8080/share/proxy/alfresco/slingshot/node/content/workspace/SpacesStore/21384098-19dc-4d3f-bcc1-9fdc647c05dc/latexexemplo.pdf

2) 捕获新内容:

从小程序中捕获用户的新文件内容。我猜你将它存储在某个字符串变量中。

3) 编辑现有文件内容:

这里的问题是您不能简单地使用任何开箱即用的 Alfresco REST API 编辑任何 pdf 文件(据我所知)。所以你需要创建自己的 RESTFul API 来编辑 pdf 文件的内容。您可以考虑使用一些第三方库来完成这项工作。您需要在 RESTFul API

中插入编辑 pdf 的逻辑

4) 改回 Repo: 在第 3 步中致电您的 API:

您也可以看看这个可以满足您要求的插件。

https://addons.alfresco.com/addons/alfresco-pdf-toolkit

希望对您有所帮助。