【问题标题】:How to upload file using LrHttp.posMultipart in Lua如何在 Lua 中使用 LrHttp.posMultipart 上传文件
【发布时间】:2016-04-09 07:28:22
【问题描述】:

我需要使用来自 Lightroom 的多部分请求将图像文件发送到使用 Lua 语言的本地 Web 服务。

我也测试过使用发送标头但不工作...

我已经创建了一个函数:

function testupload(filepath) --created inside LrTasks

local url = "http://localhosturl"
local mycontent = {
            {
                name = "lightroom_message",
                value = "sent from lightroom plugin multiparta"
            },


    {
                    name = 'file',
                    filePath = filepath,
                    fileName = LrPathUtils.leafName(filepath),
                    contentType = 'image/jpeg'
                    --contentType = 'multipart/form-data'
                }
        }

 local response, headers = LrHttp.postMultipart(url, mycontent)

结束

但是我的网络服务没有被正确调用,我正在使用 LrHttp.postMultipart() 方法来这样做..

如果我只是将这个参数发送到网络服务(然后工作正常):

{
     name = "lightroom_message",
     value = "sent from lightroom plugin multiparta"
}

但是当我包含我的文件有效负载时,它无法使用纯 Lua 实现。

【问题讨论】:

  • 这不是有效的 Lua 代码。尝试function testupload() .... end 而不是function testupload(){ ... }
  • @moteus 我知道并且我已经编辑了它......但只是想知道为什么 postMultipart 不起作用......以及我的表(mycontent)中有什么问题,它是我的发帖请求
  • “没有正确调用”是什么意思?你在哪里定义文件路径?
  • @Piglet 我在函数 testupload 中传递文件路径

标签: lua lua-table


【解决方案1】:

一切都是正确的,但只是一个技术错误...我试图从 LRtasks 内部调用 testupload() 函数..但我们不需要在单独的任务中调用它并且该函数可以完美运行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    相关资源
    最近更新 更多