我正在开发iPhone上的应用程序。
我的伴侣向我发送了一个curl命令,像这样

curl -F "clothing_item[photo]=@dress1.jpg" -F "clothing_item[name]= pink_dress" http://www......com/shop_items.json?auth_token=abc_xyz_123


并要求我实现一个功能,该功能响应将图像上传到服务器。
我尝试

forge.ajax({
    url: "http://www........com/shop_items.json",
    type: "POST",
    dataType: 'json',
    data: {
        "auth_token": token,
        "clothing_item[photo]": imageFile,
        "clothing_item[name]": id + "-" + d.getTime().toString()
    },

    success: function(data) {

    },
    error: function(error) {

    }
});


使用imageFile是相机中的文件。此帖子成功,但是没有图像上传到服务器。

还可以尝试:

forge.ajax({
    url: "http://www........com/shop_items.json",
    type: "POST",
    dataType: 'json',
    file:[imageFile];
    data: {
        "auth_token": token,
        "clothing_item[photo]": imageFile,
        "clothing_item[name]": id + "-" + d.getTime().toString()
    },

    success: function(data) {

    },
    error: function(error) {

    }
});


但这是行不通的。

任何建议表示赞赏

最佳答案

这里有一些指南可以帮助您进行调试,尽管实际上很难确切地知道问题所在。


打开Charles Proxy并运行iOS模拟器。检查在clothin_item [photo]字段上发布的内容
使用Trigger.IO Catalyst远程调试器查看“网络”选项卡,并可能手动调用类似的请求
从ajax request API来看,关键似乎实际上是“文件”而不是“文件”。如果我理解正确,则不应将图像发布在其他字段“ clothing_item [photo]”上。同样(再次,如果我理解正确的话),二进制文件字段名称为“文件”,并且无法自定义。

10-08 06:08
查看更多