通过Mirth从Dropbox读取文件

时间:2017-03-26 11:12:33

标签: dropbox dropbox-api mirth

我有一个要求,我需要读取存储在dropbox等网站中的HL7v2文件。一种方法是从该站点下载文件,并通过Sirth通过SFTP访问它。

但是这个过程很乏味,想象一下我会在一个时间点生成1000个文件,手动下载所有这些数据并从SFTP获取它将非常繁忙和耗时。 Mirth 3.4.2社区版是否具备从云存储中获取数据的能力?或者可以通过JavaScript阅读器阅读?

如果可以通过Mirth实现,请告诉我。

1 个答案:

答案 0 :(得分:1)

我不确定Dropbox是否有任何类型的本机FTP或SFTP访问层,但它确实有API和SDK:enter link description here

以下是他们展示的示例代码段:

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.ListFolderResult;
import com.dropbox.core.v2.files.Metadata;
import com.dropbox.core.v2.users.FullAccount;

import java.util.List;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

public class Main {
    private static final String ACCESS_TOKEN = "<ACCESS TOKEN>";

    public static void main(String args[]) throws DbxException, IOException {
        // Create Dropbox client
        DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
        DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);

        // Get current account info
        FullAccount account = client.users().getCurrentAccount();
        System.out.println(account.getName().getDisplayName());

        // Get files and folder metadata from Dropbox root directory
        ListFolderResult result = client.files().listFolder("");
        while (true) {
            for (Metadata metadata : result.getEntries()) {
                System.out.println(metadata.getPathLower());
            }

            if (!result.getHasMore()) {
                break;
            }

            result = client.files().listFolderContinue(result.getCursor());
        }

        // Upload "test.txt" to Dropbox
        try (InputStream in = new FileInputStream("test.txt")) {
            FileMetadata metadata = client.files().uploadBuilder("/test.txt")
                .uploadAndFinish(in);
        }
    }
}

可轻松转换为JavaScript Reader脚本:

var accessToken = '<ACCESS TOKEN>';

// Create Dropbox client
var config = new com.dropbox.core.DbxRequestConfig("dropbox/java-tutorial", "en_US");
var client = new com.dropbox.core.v2.DbxClientV2(config, accessToken);

// Get files and folder metadata from Dropbox root directory
var request = client.files();
var listResult = request.listFolder('');
var messages = new java.util.ArrayList();

while (true) {
    for each (metadata in listResult.getEntries().toArray()) {
        if (metadata instanceof com.dropbox.core.v2.files.FileMetadata) {
            try {
                var sourceMap = new java.util.HashMap();
                sourceMap.put('originalFilename', metadata.getName());
                sourceMap.put('fileDirectory', org.apache.commons.lang3.StringUtils.removeEndIgnoreCase(metadata.getPathLower(), metadata.getName()));
                sourceMap.put('fileSize', metadata.getSize());
                sourceMap.put('fileLastModified', metadata.getServerModified());
                sourceMap.put('dropboxId', metadata.getId());

                var baos = new java.io.ByteArrayOutputStream();
                var result = request.download(metadata.getId()).download(baos);

                if (result && result.getId() == metadata.getId()) {
                    messages.add(new RawMessage(baos.toByteArray(), null, sourceMap));
                }
            } catch (e) {
                logger.error('Error downloading file: ' + metadata.getPathLower(), e.javaException);
            }
        }
    }

    if (!listResult.getHasMore()) {
        break;
    }

    listResult = request.listFolderContinue(listResult.getCursor());
}

return messages;