代码之家  ›  专栏  ›  技术社区  ›  ludo

如何将画布图像数据作为附件发送到Pharo上的服务器?

  •  1
  • ludo  · 技术社区  · 6 年前

    很好用。

    ZnClient new
      url: MyUrl;
      uploadEntityfrom: FileLocator home /Path to the file;
      put
    

    在我的例子中,我不想发送/上传下载到机器上的文件,而是想发送/上传托管在某处的文件或通过网络检索到的数据,并将其连接到另一台服务器。

    1 回复  |  直到 6 年前
        1
  •  3
  •   Community CDub    4 年前

    基于你之前的问题,我推测你正在使用linux。这里的问题不在Smalltak/Pharo中,而是网络映射。

    文件传输协议

    如果你想有一个 资金转移定价 ,不要忘了它是发送明文密码,设置它的方式,你可以挂载它。可能有很多方法可以做到这一点,但你可以尝试使用 curlftpfs . 你需要内核模块 fuse 为此,一定要把它装上。如果没有加载,您可以通过 modprobe fuse .

    用法是:

    curlftpfs ftp.yoursite.net /mnt/ftp/ -o user=username:password,allow_other
    

    在哪里填充 / 密码 allow_other 允许系统中的其他用户使用您的装载。 (有关更多详细信息,请参见arch wiki及其 curlftpfs

    Webdav公司

    为了 我会使用相同的方法,这次使用 davfs

    mount

    mount -t davfs https://yoursite.net:<port>/path /mnt/webdav
    

    有两种合理的设置方法- systemd fstab davfs2

    为了 系统

    /etc/systemd/system/mnt-webdav-service.mount

    [Unit]
    Description=Mount WebDAV Service
    After=network-online.target
    Wants=network-online.target
    
    [Mount]
    What=http(s)://address:<port>/path
    Where=/mnt/webdav/service
    Options=uid=1000,file_mode=0664,dir_mode=2775,grpid
    Type=davfs
    TimeoutSec=15
    
    [Install]
    WantedBy=multi-user.target
    

    您可以创建 systemd自动安装 单位设置 :

    /etc/systemd/system/mnt-webdav-service.automount

    [Unit]
    Description=Mount WebDAV Service
    After=network-online.target
    Wants=network-online.target
    
    [Automount]
    Where=/mnt/webdav
    TimeoutIdleSec=300
    
    [Install]
    WantedBy=remote-fs.target
    

    对于 如果你已经编辑过 fstab公司 前(其行为与任何其他 fstab公司 输入):

    /etc/fstab

    https://webdav.example/path /mnt/webdav davfs rw,user,uid=username,noauto 0 0
    

    使用创建一个机密文件来存储WebDAV服务的凭据 ~/.davfs2/secrets /etc/davfs2/secrets 对于根:

    /etc/davfs2/secrets
    
    https://webdav.example/path davusername davpassword
    

    确保secrets文件包含正确的权限,以便进行根装载:

    # chmod 600 /etc/davfs2/secrets
    # chown root:root /etc/davfs2/secrets
    

    对于用户安装:

    $ chmod 600 ~/.davfs2/secrets
    

    /mnt/ftp协议 /mnt/webdav公司 安装。

    例如。 资金转移定价

    ZnClient new
      url: MyUrl;
      uploadEntityfrom: FileLocator '/mnt/ftp/your_file_to_upload';
      put
    

    以评论为基础。

    问题是 ZnClient 在Pharo本身中,json文件也在那里生成。

    一个快速而肮脏的解决方案是使用上面的命令和shell命令:

    资金转移定价 例如:

    | commandOutput |
    
    commandOutput := (PipeableOSProcess command: 'curlftpfs ftp.yoursite.net /mnt/ftp/ -o user=username:password,allow_other') output.
    Transcript show: commandOutput.
    

    另一种方法更为明智。就是用法罗 FTP WebDav 通过支持 FileSystemNetwork

    加载 仅限于:

    Gofer it
        smalltalkhubUser: 'UdoSchneider' project: 'FileSystemNetwork';
        configuration;
        load.
    #ConfigurationOfFileSystemNetwork asClass project stableVersion load: 'FTP'
    

    加载 Webdav公司 仅限于:

    Gofer it
        smalltalkhubUser: 'UdoSchneider' project: 'FileSystemNetwork';
        configuration;
        load.
    #ConfigurationOfFileSystemNetwork asClass project stableVersion load: 'Webdav'
    

    要获取包括测试在内的所有内容:

    Gofer it
        smalltalkhubUser: 'UdoSchneider' project: 'FileSystemNetwork';
        configuration;
        loadStable.
    

    这样你就可以得到一个文件,例如 ftp :

    | ftpConnection wDir file |
    
    "Open a connection"
    ftpConnection := FileSystem ftp: 'ftp://ftp.sh.cvut.cz/'.
    "Getting working directory"
    wDir := ftpConnection workingDirectory.
    file := '/Arch/lastsync' asFileReference.
    "Close connection - do always!"
    ftpConnection close.
    

    资金转移定价 )看起来像这样:

    | ftpConnection wDir file |
    
    "Open connection"
    ftpConnection := FileSystem ftp: 'ftp://your_ftp'.
    "Getting working directory"
    wDir := ftpConnection workingDirectory.
    file := '/<your_file_path' asFileReference.
    ZnClient new
         url: MyUrl;
         uploadEntityfrom: FileLocator file;
         put
    "Close connection - do always!"
    ftpConnection close.
    

    这个 Webdav公司