2

Apache Chemistry OpenCMIS を使用して Alfresco リポジトリにファイルをアップロードしようとしています。ファイルが作成され、プロパティは正しいが、コンテンツがなく、ファイルが 0 バイトです。再確認しましたが、ソース ファイルに問題はありません。ここに私のJavaコードがあります:

File content = new File(somepath);
try{
                    String mimeType = new  MimetypesFileTypeMap().getContentType(content);
                    logger.debug("mimetype: " + mimeType);
                    logger.debug("file: " + content.getAbsolutePath());
                    Map<String, Object> properties = new HashMap<String, Object>();
                    properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
                    properties.put(PropertyIds.NAME, content.getName());


                    FileInputStream fis = new FileInputStream(content);
                    DataInputStream dis = new DataInputStream(fis);
                    byte[] bytes = new byte[(int) content.length()];
                    dis.readFully(bytes);

                    ContentStream cs = new ContentStreamImpl(content.getName(), BigInteger.valueOf(bytes.length), mimeType, dis);
                    Folder folder = (Folder) session.getObjectByPath("/myfolder");
                    Document doc = folder.createDocument(properties, cs, VersioningState.MAJOR);
                    return doc.getId();
                }catch(CmisBaseException e){
                    logger.error("error uploading file: "+ e.getMessage(), e);
                }

キャッチされた例外はありません。

4

2 に答える 2

4

渡されたコンテンツ ストリームに問題があると思います。

コードをこれに置き換えてみてください

String docText = "This is a sample document";
byte[] content = docText.getBytes();
InputStream stream = new ByteArrayInputStream(content);
ContentStream contentStream = getSession().getObjectFactory().createContentStream(filename, Long.valueOf(content.length), "text/plain", stream);

次のステップで、この単純なテキストを新しいファイルの内容で徐々に変更できます。

于 2013-04-19T05:43:10.387 に答える
1

私はこれについての例を探していましたが、あなたの質問を見つけました.私が間違っていなければオリジナルの問題は、あなたがバッファを事前に読んでいるので、コンテンツストリームに渡すときにポインタが最後にあるということです.後でプログラムに実装したい機能をテストするためだけに小さなクラスを作成していますが、このブロックは最初のアプローチで機能します。

File content = new File("C:\\\\asdf.asdf");
    try{
        String mimeType = new  MimetypesFileTypeMap().getContentType(content);
        System.out.println("mimetype: " + mimeType);
        System.out.println("file: " + content.getAbsolutePath());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.OBJECT_TYPE_ID,BaseTypeId.CMIS_DOCUMENT.value()+",P:cm:titled");
        properties.put("cm:description", "upload desde código");
        properties.put(PropertyIds.NAME, content.getName());
        FileInputStream fis = new FileInputStream(content); 
        DataInputStream dis = new DataInputStream(fis);                    
        ContentStream cs = new ContentStreamImpl(content.getName(),BigInteger.valueOf(content.length()), mimeType, dis);
        Document doc = newFolder.createDocument(properties, cs, VersioningState.MAJOR);
    }catch(CmisBaseException ex){
        Logger.getLogger(CMISTest.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(CMISTest.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(CMISTest.class.getName()).log(Level.SEVERE, null, ex);
    }
于 2013-10-28T23:30:46.703 に答える