通过莲花脚本从url下载图片 [英] Picture download from url via lotus script

查看:195
本文介绍了通过莲花脚本从url下载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从url下载一张图片到我的Lotus Notes应用程序。
我可以从url获取文本字段,但图像很困难。
我尝试将图片放在一个富文本字段,但它不起作用。
任何想法?

I want to download one picture from url to my Lotus Notes application. I can get text field from url, but image is difficult. I try to put pic to a rich text field, but it doesn't work. Any idea?

推荐答案

您可以通过LotusScript从一个脚本库键入Java。

You can download an image from URL via LotusScript with the help of a little Script Library of type "Java".

创建类型Java的脚本库GetImageFromUrl,并输入以下代码:

Create a Script Library "GetImageFromUrl" of Type "Java" and put in following code:

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class GetImageFromUrl {

    public static boolean getImageFromUrl(String imageUrl, String filePath) {
        try {
            URL url = new URL(imageUrl);
            InputStream is = url.openStream();
            OutputStream os = new FileOutputStream(filePath);
            byte[] b = new byte[2048];
            int length;
            while ((length = is.read(b)) != -1) {
                os.write(b, 0, length);
            }
            is.close();
            os.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

然后可以使用该方法您的LotusScript代码中的 getImageFromUrl(imageUrl,filePath)将图像下载到文件。从那里,您可以使用 rtitem.EmbedObject(EMBED_ATTACHMENT,,c:/temp/image.jpg)将图像文件附加到RichText项目。

Then you can use the method getImageFromUrl(imageUrl, filePath) in your LotusScript code to download the image to a file. From there you can attach the image file to a RichText item with rtitem.EmbedObject(EMBED_ATTACHMENT, "", "c:/temp/image.jpg").

Option Declare

UseLSX "*javacon"  

Use "GetImageFromUrl"

Sub Initialize
    dim jSession As New JavaSession
    dim jClass As JavaClass
    Set jClass = jSession.GetClass( "GetImageFromUrl" )     
    If jClass.getImageFromUrl("https://your.url", "c:/temp/image.jpg") Then
        MessageBox "File is downloaded"
    End If
End Sub

这篇关于通过莲花脚本从url下载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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