使用版本在 alfresco 中保存文件并下载最新版本 [英] saving file in alfresco with Version and Download the latest version

查看:28
本文介绍了使用版本在 alfresco 中保存文件并下载最新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 alfresco Community 4.0,我使用了这个 jar alfresco-web-service-client-4.0.d.jar

使用此代码,我可以在 alfresco 中保存我的 test.pdf 文件:

File file = new File("C:/test.pdf");saveAttachement(file,"test.pdf", "/app:company_home/cm:MyFolder",管理员",管理员")public String saveAttachement(文件文件,字符串名称,字符串文件夹名称,字符串用户名,字符串密码)抛出异常{byte[] contentByte = IOUtils.toByteArray(new FileInputStream(file));//开始会话AuthenticationUtils.startSession(userName, pwd);尝试 {//创建对要在其中创建内容的父级的引用Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");ParentReference companyHomeParent = new ParentReference(storeRef, null, folderName, Constants.ASSOC_CONTAINS, null);//赋值companyHomeParent.setChildName("cm:" + name);//构造CML语句来创建内容节点//注意:将1"赋值为本地id,后续可以参考//同一 CML 块中的 CML 语句NamedValue[] contentProps = new NamedValue[1];contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, name);CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_CONTENT, contentProps);//构造 CML 语句以添加标题方面NamedValue[] titledProps = new NamedValue[2];titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, name);titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, name);CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");//构造 CML 块CML CML = 新 CML();cml.setCreate(new CMLCreate[] { 创建 });cml.setAddAspect(new CMLAddAspect[] { addAspect });//通过 Repository Web Service 发出 CML 语句并检索结果//注意:将多个语句批处理为单个 Web 调用UpdateResult[] 结果 = WebServiceFactory.getRepositoryService().update(cml);参考内容 = 结果[0].getDestination();//写一些内容ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();//String text = "敏捷的棕色狐狸跳过懒狗";ContentFormat contentFormat = new ContentFormat("text/plain", "UTF-8");内容 contentRef = contentService.write(content, Constants.PROP_CONTENT, contentByte, contentFormat);System.out.println("文档创建成功.UID:= " + content.getUuid());返回 content.getUuid();} catch (Throwable e) {System.out.println(e.toString());} 最后 {//结束会话AuthenticationUtils.endSession();//System.exit(0);}返回空;}

在露天保存这个文件后,我有这个 ID d7633eff-8595-4d6c-8c18-a29a656607ba

稍后将用于下载此文件

这是下载代码:

ContentResult contentResult = getContentsById("d7633eff-8595-4d6c-8c18-a29a656607ba", "admin", "admin");public ContentResult getContentsById(String contentId, String userName, String pwd)抛出异常{ContentResult contentResult = new ContentResult();//开始会话AuthenticationUtils.startSession(userName, pwd);尝试 {Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();参考 contentReference = new Reference(storeRef, contentId, null);内容[] readResult = null;尝试 {readResult = contentService.read(new Predicate(new Reference[] { contentReference }, storeRef, null), Constants.PROP_CONTENT);} 抓住(内容错误 e){e.printStackTrace();} catch (RemoteException e) {e.printStackTrace();}if ((readResult != null) && (readResult[0] != null)) {内容 content = readResult[0];ContentFormat cnf = content.getFormat();参考 ref = content.getNode();String[] splitedUrl = content.getUrl().split("/");字符串名称 = splitedUrl[splitedUrl.length - 1];InputStream 是 = ContentUtils.getContentAsInputStream(content);byte[] contentByte = ConvertUtil.convertInputStreamToByte(is);contentResult.setName(name);contentResult.setMimetype(cnf.getMimetype());contentResult.setId(ref.getUuid());contentResult.setUrl(content.getUrl());contentResult.setPath(ref.getPath());contentResult.setContentByte(contentByte);System.out.println("文档已被检索");}} 捕获(异常 e){System.out.println(e.toString());} 最后 {//结束会话AuthenticationUtils.endSession();//System.exit(0);}返回内容结果;}

目前我更改了 test.pdf 文件内容而不更改文件名我把它放在光盘中的另一个位置.

这是新的文件位置.

C:/version/test.pdf

所以在磁盘中我有两个名称相同但内容不同的文件.

我的目标是在 alfresco 中保存新文件,但使用版本控制.

在我看来,我必须使用在 alfresco 中保存的旧 ID:d7633eff-8595-4d6c-8c18-a29a656607ba

所以我应该开发一种将新文件和旧 ID 作为参数的方法

喜欢这个

 File file = new File("C:/version/test.pdf");saveWithVersionAttachement(file,"d7633eff-8595-4d6c-8c18-a29a656607ba","test.pdf", "/app:company_home/cm:MyFolder","管理员", "管理员",)public String saveWithVersionAttachement(文件文件,String oldId,String name,String folderName,String userName,String pwd)抛出异常{………………………………

在我看来,这种方法必须像这样 test_2.pdf 或 test_v2.pdf ..

所以这两个文件保存在 alfresco 并且具有相同的 id

在下载方法中我想要最新版本.

所以我必须改变方法 getContentById ("d7633eff-8595-4d6c-8c18-a29a656607ba", "admin", "admin");

为了返回最新版本,即test_2.pdf 或 test_v2.pdf ...

我尝试使用 alfresco-OpenCMIS-extension-0.7.jar 来使用 OpenCMIS,但没有成功

我在 Alfresco omcatwebappsalfrescoWEB-INFclassesalfrescomodelcontentModel.xml 中添加了这一行

<aspect>cm:versionable</aspect></mandatory-aspects>

我还添加了这一行 version.store.enableAutoVersioning=true

Alfresco omcatsharedclassesalfresco-global.properties

有谁能帮我解决我的问题

更新:

我在 CMIS 工作:

我尝试使用此代码:

import java.io.ByteArrayInputStream;导入 java.io.File;导入 java.io.FileInputStream;导入 java.io.IOException;导入 java.io.InputStreamReader;导入 java.io.Reader;导入 java.util.HashMap;导入 java.util.List;导入 java.util.Map;导入 org.apache.chemistry.opencmis.client.api.Document;导入 org.apache.chemistry.opencmis.client.api.Repository;导入 org.apache.chemistry.opencmis.client.api.Session;导入 org.apache.chemistry.opencmis.client.api.SessionFactory;导入 org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;导入 org.apache.chemistry.opencmis.commons.SessionParameter;导入 org.apache.chemistry.opencmis.commons.data.ContentStream;导入 org.apache.chemistry.opencmis.commons.enums.BindingType;导入 org.apache.commons.io.IOUtils;public void saveVersioning(文件文件,字符串文件名,字符串用户名,字符串密码,字符串docId)抛出异常{SessionFactory 工厂 = SessionFactoryImpl.newInstance();映射<字符串,字符串>参数 = new HashMap();//用户凭据.parameters.put(SessionParameter.USER,userName);parameters.put(SessionParameter.PASSWORD, pwd);//连接设置.parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:9080/alfresco/service/cmis");//指向您的 CMIS 服务器的 URL.parameters.put(SessionParameter.AUTH_HTTP_BASIC, "true" );//创建会话.//Alfresco 只提供一个仓库.存储库存储库 = factory.getRepositories(parameters).get(0);会话会话 = repository.createSession();//获取文件内容文档 doc = (Document) session.getObject(docId);ContentStream contentStream = doc.getContentStream();//如果文档没有内容,则返回 null如果(内容流!= null){String mimetype = "text/plain; charset=UTF-8";字符串内容 = "";如果(内容流!= null){文件名 = contentStream.getFileName();mimetype = contentStream.getMimeType();content = getContentAsString(contentStream);System.out.println("文件名"+文件名);System.out.println("minetype"+mimetype);System.out.println("内容"+内容);}byte[] buf = IOUtils.toByteArray(new FileInputStream(file));ByteArrayInputStream input = new ByteArrayInputStream(buf);contentStream = session.getObjectFactory().createContentStream(文件名、buf.length、mimetype、输入);System.out.println("文档版本历史");{列表<文档>版本 = doc.getAllVersions();对于(文档版本:版本){System.out.println("	name:" + version.getName());System.out.println("	version 标签:" + version.getVersionLabel());System.out.println("	version 系列id:" + version.getVersionSeriesId());System.out.println("	检出:"+ version.getVersionSeriesCheckedOutBy());System.out.println("	checked id: "+ version.getVersionSeriesCheckedOutId());System.out.println("	主要版本:" + version.isMajorVersion());System.out.println("最新版本:" + version.isLatestVersion());System.out.println("最新主要版本:" + version.isLatestMajorVersion());System.out.println("	checkin 注释:" + version.getCheckinComment());System.out.println("	内容长度:" + version.getContentStreamLength()+ "
");}}}}私有静态字符串 getContentAsString(ContentStream stream) 抛出 IOException {StringBuilder sb = new StringBuilder();Reader reader = new InputStreamReader(stream.getStream(), "UTF-8");尝试 {最终字符 [] 缓冲区 = 新字符 [4 * 1024];国际b;而(真){b = reader.read(buffer, 0, buffer.length);如果 (b > 0) {sb.append(buffer, 0, b);} else if (b == -1) {休息;}}} 最后 {reader.close();}返回 sb.toString();}

我使用此代码调用此函数:

File file = new File("C:/version/test.pdf");saveVersioning(文件,test.pdf",admin",admin",d7633eff-8595-4d6c-8c18-a29a656607ba");

我用过这个罐子:

chemistry-opencmis-client-api-0.13.0.jar化学-opencmis-client-bindings-0.13.0.jar化学-opencmis-client-impl-0.13.0.jar化学-opencmis-commons-api-0.13.0.jar化学-opencmis-commons-impl-0.13.0.jarcommons-io-1.4.jarslf4j-api-1.7.5.jarstax2-api-3.1.4.jarwoodstox-core-asl-4.4.0.jar

但是当我尝试测试时出现此错误:

Caused by: java.lang.NoClassDefFoundError: org/apache/chemistry/opencmis/client/api/SessionFactory………………………………引起:java.lang.ClassNotFoundException:org.apache.chemistry.opencmis.client.api.SessionFactory在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)... 124 更多

解决方案

实现这一目标的最快和最简单方法是利用 RESTfull API

这也将确保与新版本的 alfresco 兼容.

请注意,您需要在表单属性 updatenoderef 中提供要更新的文档的 noderef,并且属性 majorversion 是一个布尔标志,用于指定新版本是文档的次要/主要版本.

以下示例代码可能对您的用例有所帮助:

 CloseableHttpClient httpClient = HttpClients.createDefault();HttpPost uploadFile = new HttpPost(+"/api/upload?alf_ticket="+);MultipartEntityBuilder builder = MultipartEntityBuilder.create();builder.addTextBody("username", "", ContentType.TEXT_PLAIN);builder.addTextBody("updatenoderef", , 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);如果 (response.getStatusLine().getStatusCode()!=200){throw new Exception("无法将文件上传到存储库,网页脚本响应:" + responseString );}

注意 1:您需要将这些标记 <*> 替换为您自己的值/变量

注意 2:如果您在检索票证时遇到问题,请查看 这个链接,或者这个

I work with alfresco Community 4.0 and I used this jar alfresco-web-service-client-4.0.d.jar

using this code I can save my test.pdf file in alfresco :

File file = new File("C:/test.pdf");

  saveAttachement(file,"test.pdf", "/app:company_home/cm:MyFolder",
                        "admin", "admin")



                         public String saveAttachement(File file, String name, String folderName, String userName, String pwd)
        throws Exception {


        byte[] contentByte = IOUtils.toByteArray(new FileInputStream(file));

        // Start the session
        AuthenticationUtils.startSession(userName, pwd);

        try {
            // Create a reference to the parent where we want to create content
            Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            ParentReference companyHomeParent = new ParentReference(storeRef, null, folderName, Constants.ASSOC_CONTAINS, null);

            // Assign name
            companyHomeParent.setChildName("cm:" + name);

            // Construct CML statement to create content node
            // Note: Assign "1" as a local id, so we can refer to it in subsequent
            //       CML statements within the same CML block
            NamedValue[] contentProps = new NamedValue[1];
            contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, name);

            CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_CONTENT, contentProps);

            // Construct CML statement to add titled aspect
            NamedValue[] titledProps = new NamedValue[2];
            titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, name);
            titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, name);

            CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");

            // Construct CML Block
            CML cml = new CML();
            cml.setCreate(new CMLCreate[] { create });
            cml.setAddAspect(new CMLAddAspect[] { addAspect });

            // Issue CML statement via Repository Web Service and retrieve result
            // Note: Batching of multiple statements into a single web call
            UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
            Reference content = result[0].getDestination();

            // Write some content
            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();

            //String text = "The quick brown fox jumps over the lazy dog";
            ContentFormat contentFormat = new ContentFormat("text/plain", "UTF-8");
            Content contentRef = contentService.write(content, Constants.PROP_CONTENT, contentByte, contentFormat);
            System.out.println("Document are created successfully. UID:= " + content.getUuid());

            return content.getUuid();
        } catch (Throwable e) {
            System.out.println(e.toString());
        } finally {
            // End the session
            AuthenticationUtils.endSession();

            //System.exit(0);
        }

        return null;
    }

after saving this file in alfresco I have this id d7633eff-8595-4d6c-8c18-a29a656607ba

it will be used later to download this file

This is the download code :

ContentResult contentResult = getContentsById("d7633eff-8595-4d6c-8c18-a29a656607ba", "admin", "admin");


       public ContentResult getContentsById(String contentId, String userName, String pwd)
        throws Exception {
        ContentResult contentResult = new ContentResult();

        // Start the session
        AuthenticationUtils.startSession(userName, pwd);

        try {
            Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();

            Reference contentReference = new Reference(storeRef, contentId, null);
            Content[] readResult = null;

            try {
                readResult = contentService.read(new Predicate(new Reference[] { contentReference }, storeRef, null), Constants.PROP_CONTENT);
            } catch (ContentFault e) {
                e.printStackTrace();
            } catch (RemoteException e) {
                e.printStackTrace();
            }

            if ((readResult != null) && (readResult[0] != null)) {
                Content content = readResult[0];
                ContentFormat cnf = content.getFormat();
                Reference ref = content.getNode();

                String[] splitedUrl = content.getUrl().split("/");
                String name = splitedUrl[splitedUrl.length - 1];

                InputStream is = ContentUtils.getContentAsInputStream(content);
                byte[] contentByte = ConvertUtil.convertInputStreamToByte(is);

                contentResult.setName(name);
                contentResult.setMimetype(cnf.getMimetype());
                contentResult.setId(ref.getUuid());
                contentResult.setUrl(content.getUrl());
                contentResult.setPath(ref.getPath());
                contentResult.setContentByte(contentByte);
                System.out.println(" document has been retrieved");
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        } finally {
            // End the session
            AuthenticationUtils.endSession();

            // System.exit(0);
        }

        return contentResult;
    }

currently I change the test.pdf file content without changing the file name and I put it in another location in the disc.

This is the new file location.

C:/version/test.pdf

So in the disk I have two files with the same name but with different content.

my goal is to save the new file in alfresco but using versioning.

in my opinion I must use the old id which is saving in alfresco : d7633eff-8595-4d6c-8c18-a29a656607ba

so I should develop a method that takes as a parameter the new file and the old id

like this

 File file = new File("C:/version/test.pdf");

  saveWithVersionAttachement(file,"d7633eff-8595-4d6c-8c18-a29a656607ba","test.pdf", "/app:company_home/cm:MyFolder",
                        "admin", "admin",)



                         public String saveWithVersionAttachement(File file,String oldId, String name, String folderName, String userName, String pwd)
        throws Exception {
 .............
 .............

in my opinion this method must save the new file in alfresco like this test_2.pdf or test_v2.pdf ..

so the two files are saved in alfresco and having the same id

and in the download method I want to have the latest version.

so I must change the method getContentById ("d7633eff-8595-4d6c-8c18-a29a656607ba", "admin", "admin");

in order to return the latest version which is test_2.pdf or test_v2.pdf ...

I tried unsuccessfully to work with OpenCMIS using alfresco-OpenCMIS-extension-0.7.jar

I added this lines in Alfresco omcatwebappsalfrescoWEB-INFclassesalfrescomodelcontentModel.xml

<mandatory-aspects>
<aspect>cm:versionable</aspect>
</mandatory-aspects>

also I added this line version.store.enableAutoVersioning=true

in Alfresco omcatsharedclassesalfresco-global.properties

is there anyone who can help me to solve my problem

UPDATED :

I work with CMIS :

I try with this code :

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.commons.io.IOUtils;


     public void saveVersioning(File file, String filename, String userName, String pwd, String docId)
            throws Exception {

            SessionFactory factory = SessionFactoryImpl.newInstance();
            Map<String, String> parameters = new HashMap<String, String>();

            // User credentials.
            parameters.put(SessionParameter.USER,userName);
            parameters.put(SessionParameter.PASSWORD, pwd);

            // Connection settings.
            parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
            parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:9080/alfresco/service/cmis"); // URL to your CMIS server.
            parameters.put(SessionParameter.AUTH_HTTP_BASIC, "true" );

            // Create session.
            // Alfresco only provides one repository.
            Repository repository = factory.getRepositories(parameters).get(0);

            Session session = repository.createSession();

             // Get the contents of the file
            Document doc = (Document) session.getObject(docId);
            ContentStream contentStream = doc.getContentStream(); // returns null if the document has no content
            if (contentStream != null) {


                    String mimetype = "text/plain; charset=UTF-8";
                    String content = "";

                    if (contentStream != null) {
                        filename = contentStream.getFileName();
                        mimetype = contentStream.getMimeType();
                        content = getContentAsString(contentStream);
                        System.out.println("file name "+filename);
                        System.out.println("minetype "+mimetype);
                        System.out.println("content "+content);
                    }


                    byte[] buf = IOUtils.toByteArray(new FileInputStream(file));
                    ByteArrayInputStream input = new ByteArrayInputStream(buf);

                    contentStream = session.getObjectFactory().createContentStream(
                            filename, buf.length, mimetype, input);



                    System.out.println("Document version history");
                    {
                        List<Document> versions = doc.getAllVersions();
                        for (Document version : versions) {
                            System.out.println("	name: " + version.getName());
                            System.out.println("	version label: " + version.getVersionLabel());
                            System.out.println("	version series id: " + version.getVersionSeriesId());
                            System.out.println("	checked out by: "
                                    + version.getVersionSeriesCheckedOutBy());
                            System.out.println("	checked out id: "
                                    + version.getVersionSeriesCheckedOutId());
                            System.out.println("	major version: " + version.isMajorVersion());
                            System.out.println("	latest version: " + version.isLatestVersion());
                            System.out.println("	latest major version: " + version.isLatestMajorVersion());
                            System.out.println("	checkin comment: " + version.getCheckinComment());
                            System.out.println("	content length: " + version.getContentStreamLength()
                                    + "
");
                        }
                    }
                }



        }



    private static String getContentAsString(ContentStream stream) throws IOException {
        StringBuilder sb = new StringBuilder();
        Reader reader = new InputStreamReader(stream.getStream(), "UTF-8");

        try {
            final char[] buffer = new char[4 * 1024];
            int b;
            while (true) {
                b = reader.read(buffer, 0, buffer.length);
                if (b > 0) {
                    sb.append(buffer, 0, b);
                } else if (b == -1) {
                    break;
                }
            }
        } finally {
            reader.close();
        }

        return sb.toString();
    }

I call this fonction using this code :

File file = new File("C:/version/test.pdf");

saveVersioning(file, "test.pdf","admin","admin","d7633eff-8595-4d6c-8c18-a29a656607ba");

I used this jar :

chemistry-opencmis-client-api-0.13.0.jar
chemistry-opencmis-client-bindings-0.13.0.jar
chemistry-opencmis-client-impl-0.13.0.jar
chemistry-opencmis-commons-api-0.13.0.jar
chemistry-opencmis-commons-impl-0.13.0.jar
commons-io-1.4.jar
slf4j-api-1.7.5.jar
stax2-api-3.1.4.jar
woodstox-core-asl-4.4.0.jar

but when I try to test I have this error :

Caused by: java.lang.NoClassDefFoundError: org/apache/chemistry/opencmis/client/api/SessionFactory
.............
............
Caused by: java.lang.ClassNotFoundException: org.apache.chemistry.opencmis.client.api.SessionFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    ... 124 more

解决方案

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

这篇关于使用版本在 alfresco 中保存文件并下载最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆